我正在使用fluidRow/Column布局创建一个闪亮的应用程序!
在第一行中,我想包含一个包含一个图像图的输出!第二行包含更多绘图和无功输入(selectInput).
无论我尝试什么(renderPLot,renderImage,renderUI)来返回绘图,我总是在第一行下面的一个空白处打开行 - .-
请注意,我为第一行中的绘图提供了绘图功能.情节本身看起来很完美,它只是情节下方的白色空间......
有什么建议可能是这种行为的原因以及如何摆脱空白?
谢谢 !
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
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
HTML代码
无论出于何种原因,放置图像的div的高度不会调整大小,因为图像大小调整为400x150.
我们可以通过使用HTML函数将图像放入div中,使用一些内联CSS将高度固定为150px(或者您想要的任何其他内容)来为此做一个hacky修复.
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)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3520 次 |
| 最近记录: |