【问题标题】:Render multiple images in R shinydashboard在 R shinydashboard 中渲染多个图像
【发布时间】:2021-03-04 08:40:40
【问题描述】:

R,shinydashboard 中是否有任何方法可以根据selectinput 选项在仪表板主体中呈现多个图像?

这是我的代码:

library(shiny)
library(shinydashboard)

images_a <- list.files("input/plots 1/", pattern = ".png") # 6 'png' images are in the *input/plots 1* folder
images_b <- list.files("input/plots 1/", pattern = ".jpg") # 5 'jpg' images are in the *input/plots 1* folder

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(selectInput(inputId = "image_type", label = "Image type", choices = c("png", "jpg"), selected = "png")),
  dashboardBody()
)

server <- function(input, output) {
}

shinyApp(ui, server)

谢谢!

【问题讨论】:

    标签: r shiny shinydashboard


    【解决方案1】:

    使用lapply( )循环进入renderImage( )

    download.file("http://dehayf5mhw1h7.cloudfront.net/wp-content/uploads/sites/38/2016/01/18220900/Getty_011816_Bluepenguin.jpg",
                      destfile = "Bowie.png")
        download.file("http://3.bp.blogspot.com/_cBH6cWZr1IU/TUURNp7LADI/AAAAAAAABsY/76UhGhmxjzY/s640/penguin+cookies_0018.jpg",
                      destfile = "Cookie.png")
        
        function(input, output) {
        
          output$img1 <- renderImage({   #This is where the image is set 
            if(input$var == "Bowie"){            
              list(src = "Bowie.png", height = 240, width = 300)
            }                                        
            else if(input$var == "Cookie"){
              list(src = "Cookie.png", height = 240, width = 300)
            }
            else if(input$var == "Renesme"){
              list(src = "Renesme.png", height = 240, width = 300)
            }
            else if(input$var == "Mango"){
              list(src = "Mango.png", height = 240, width = 300)
            }
          })
    

    【讨论】:

    • 谢谢Ujjawal Bhandari,你知道如何循环renderImage吗?
    • 下面附两张图。
    猜你喜欢
    • 1970-01-01
    • 2021-09-12
    • 2020-11-08
    • 2015-01-31
    • 2023-03-11
    • 2020-06-19
    • 1970-01-01
    • 1970-01-01
    • 2014-02-03
    相关资源
    最近更新 更多