【问题标题】:Load Shinydashboard Image加载 Shinydashboard 图像
【发布时间】:2018-05-04 20:54:06
【问题描述】:
我正在尝试将图像加载到我的闪亮仪表板中,当图像呈现时,我在图像中心看到一个蓝色问号。我在我的工作目录中创建了一个 www 文件夹,并将 png 放在该文件夹中。
到目前为止,我对此选项卡的布局只是:
tabItem(tabName = "Alignment",
fluidRow(
tags$img(src = 'Alignment.png', height = 800, width = 1200)
)
),
标签名称显示在我的闪亮仪表板中,它会尝试加载图像并在我更改它时调整它的大小,但它不会加载任何内容。
关于为什么会这样的任何建议?
【问题讨论】:
标签:
r
shiny
shinydashboard
【解决方案1】:
你需要把图片放到服务端去渲染。
试试这个:
library (shiny)
library (shinydashboard)
library (png)
###/UI SIDE/###
header <- dashboardHeader()
sidebar <- dashboardSidebar(
sidebarMenu(id = "test",
menuItem("Alignment", tabname = "AlignmentTab")
)
)
body <- dashboardBody(
tabItem(tabName = "AlignmentTab",
fluidRow(
box(
title = "Alignment", status = "primary", solidHeader = TRUE, width = 12,
imageOutput("Alignment", height = "auto")
)
)
)
)
ui <- dashboardPage(header, sidebar, body)
###/SERVER SIDE/###
server <- function(input, output, session) {
output$picture <- renderImage({
return(list(src = "/srv/samba/share/site layouts//Alignment.PNG",contentType = "image/png",alt = "Alignment"))
}, deleteFile = FALSE) #where the src is wherever you have the picture
}
#Combines Dasboard and Data together----
shinyApp(ui, server)
【解决方案2】:
我尝试了上面的答案。有效。我只需要稍微调整一下,因为我相信imageOutput() 命令的参数应该是imageOutput("picture", height = "auto") 而不是imageOutput("Alignment", height = "auto")。