加载Shinydashboard图像

时间:2018-05-04 20:54:07

标签: r shiny shinydashboard

我正在尝试将图像加载到我的shinydashboard中,当图像呈现时,我在图像的中心会出现一个蓝色问号。我在工作目录中创建了一个www文件夹,并将png放在该文件夹中。

到目前为止,此标签的布局只是:

<div class="header">
  <p class="description">Description</p>
  <h3 class="main title">Category</h3>
</div>

选项卡名称显示在我的shinydashboard中,它会尝试加载图像,如果我更改它会调整它的大小,但它不会加载任何内容。

有关这个原因的建议吗?

2 个答案:

答案 0 :(得分: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)

答案 1 :(得分:0)

我尝试了以上答案。有效。我只需要稍作调整,因为我相信在imageOutput()命令中,参数应为imageOutput("picture", height = "auto")而不是imageOutput("Alignment", height = "auto")