我在网上搜索了很多类似的问题但都没有找到与我的情况相符的答案。我对Shiny非常陌生,所以希望你们能帮助我。下面是我编写的代码。我在本地文件夹中有许多png文件的标题格式如下:“CountyX reasonY.png”(文件扩展名前有一个空格),在UI中,你可以看到在下拉菜单中选择多个县和原因进行组合。
我想做的是能够将多个图像呈现在栅格中,以便比较各县和原因的组合(即在2x2网格(如果有12个,则为3x4)中查看County2 reason1、County1 reason3、County2 reason3和County4 reason2等)。为了使它更容易,我已经上传了一些png文件供实验使用:PNG 1,PNG 2,PNG 3,PNG 4。
我尝试过的output$plots仅适用于显示一个图像。
library(shiny)
library(shinyWidgets)
ui <- fluidPage(
titlePanel("Compare"),
sidebarLayout(
sidebarPanel(
pickerInput(inputId = "countyInput", label = "Filter county",
choices = c("County1", "County2", "County3", "County4", "County5"),
options = list(`actions-box` = TRUE,size = 10, `selected-text-format` = "count > 9"),
multiple = TRUE),
checkboxGroupInput(inputId = "reasonInput", label = "Filter reason",
choices = c("reason1", "reason2", "reason3"))
),
mainPanel(
plotOutput("plot")
)
)
)
server <- function(input, output, session) {
output$plot <- renderImage({
filename <- normalizePath(file.path("<local path name to png files>", paste(input$countyInput, " ", input$reasonInput, " .png", sep = "")))
list(src = filename)
}, deleteFile = FALSE)
}
shinyApp(ui = ui, server = server)
感谢您的所有帮助。
width
。如 https://shiny.rstudio.com/reference/shiny/0.14/renderPlot.html 所述,您可以使用反应性值来指定宽度。因此,也许可以为图像数量创建一个反应表达式,并在指定nrow
和width
时使用它。 - annhakwidth
属性会使窗口可以滚动,而不会裁剪图像。 - annhak