tutorial publicar examples ejemplos app r shiny

publicar - Shiny R: espacio en blanco no deseado en fluidRow



shiny r tutorial (1)

Por alguna razón, la altura del div en el que se coloca la imagen no cambia de tamaño a medida que la imagen cambia de tamaño a 400x150.

Podemos hacer una especie de solución hacky para esto mediante el uso de la función HTML para poner la imagen en un div con CSS en línea que corrige la altura en 150px (o cualquier otra cosa que desee).

library(shiny) plotFunction <- function(col_palette) { mtrx = matrix(c(1,2,3,4),nrow = 4, ncol =3 ,byrow = T) par(oma = c(0,0,0,0),mar=c(2,2,0,2)) image( mtrx, col = col_palette, xlab="", ylab = "", axes = F ) } # ned of plotFunction.R server <- shinyServer(function(input, output) { output$plot1 <- renderPlot({ plotFunction(col_palette = heat.colors(4)) }, width = 400, height = 150) # end of renderPlot }) # end of shinyServer ui <- shinyUI( fluidPage( # 1st row fluidRow( column(12, HTML("<div style=''height: 150px;''>"), plotOutput("plot1"), HTML("</div>") ) ), # 2nd row fluidRow( column(1, selectInput("someSelection", label = "Select smth", choices = c("smth","smth more") ), selectInput("anotherSelection", label = "Select more", choices = c("more","and more") ) ) # end of column ) # end of fluidRow ) # end of fluidPage ) # end of shiny UI shinyApp(ui = ui, server = server)

¡Estoy creando una aplicación brillante usando un diseño fluidRow / Column!

¡En la primera fila me gustaría incluir una salida que contenga un gráfico de imagen! La segunda fila contiene gráficos adicionales e entradas reactivas (selectInput).

No importa lo que intento (renderPLot, renderImage, renderUI) para devolver la trama, siempre obtengo un espacio en blanco debajo de la primera fila que hace saltar la fila -.-

Tenga en cuenta que fuente la función de trazado para la gráfica en la primera fila. La trama en sí se ve perfectamente bien, es solo el espacio en blanco debajo de la trama ...

¿Alguna sugerencia cuál podría ser la razón de este comportamiento y cómo deshacerse de los espacios en blanco?

Gracias !

Server.R

source("plotFunction.R") shinyServer(function(input, output) { output$plot1 <- renderImage({ outfile <- tempfile(fileext=''.png'') png(outfile, width=400, height=150) plotFunction(col_palette = heat.colors(4)) dev.off() # Return a list containing the filename list(src = outfile, contentType = ''image/png'', width = 400, height = 150) }, deleteFile = TRUE) # end of render image }) # end of shinyServer

UI.R

shinyUI(fluidPage( # 1st row fluidRow( column( 12, align = "center", imageOutput("plot1") ) # end of column ), # end of 1st row # 2nd row fluidRow( column( 1, selectInput("someSelection", label = "Select smth", choices = c("smth","smth more") ), selectInput("anotherSelection", label = "Select more", choices = c("more","and more") ) ) # end of column ) # end of fluidRow )) # end of shiny UI

plotFunction.R

plotFunction <- function(col_palette) { mtrx = matrix(c(1,2,3,4),nrow = 4, ncol =3 ,byrow = T) par(oma = c(0,0,0,0),mar=c(2,2,0,2)) image( mtrx, col = col_palette, xlab="", ylab = "", axes = F ) } # ned of plotFunction.R

código HTML