【问题标题】:R shinydashboard fit image into box elementR shinydashboard 将图像适合框元素
【发布时间】:2020-06-20 22:27:49
【问题描述】:

我有一个闪亮的仪表板应用程序,它基于过滤器呈现图像,因此根据过滤器中选择的值,图像会显示在框内。但是,有些图像太大并且在框外渲染,这意味着框不包含整个图像。

如果我尝试使用 img(src="imagename", height = 200) 显示相同的图像,图像会自动适合框。如何使用 imageOutput() 函数复制相同的内容?

这里是代码的外观:

library("shiny")
library("shinydashboard")

sidebar <- dashboardSidebar()

body <- dashboardBody(
    fluidRow(
        box(imageOutput("image")) # IMAGE TOO BIG AND BOX CANNOT COMPLETELY CONTAIN IT
        img(src="imagename", height = 200) # Image adjusted to box size

    )
)


ui <- dashboardPage(dashboardHeader(title = "Example"),
                    sidebar,
                    body
)

server <- function(input, output) {

 output$image <- renderImage({

    filename <- normalizePath(file.path(paste('www/',imagename, '.png', sep='')))
        list(src = filename)},
        deleteFile = FALSE)
}) 
}

shinyApp(ui, server)

【问题讨论】:

    标签: r shiny shinydashboard


    【解决方案1】:

    您可以在返回的列表中设置高度renderImage

    output$image <- renderImage({
      filename <- normalizePath(file.path(paste0('www/', imagename, '.png')))
      list(
        src = filename, 
        height = 200
      )
    }, deleteFile = FALSE)
    

    【讨论】:

      猜你喜欢
      • 2020-11-29
      • 1970-01-01
      • 1970-01-01
      • 2016-03-11
      • 2019-05-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-23
      相关资源
      最近更新 更多