简体   繁体   English

Shinydashboard 选项卡上的不同背景

[英]Different backgrounds on shinydashboard tabs

I would like to create a shinydashboard where the background of the first tab contains a picture, stored locally, and the remaining tabs contain a plain white background.我想创建一个闪亮的仪表板,其中第一个选项卡的背景包含本地存储的图片,其余选项卡包含纯白色背景。

I tried to modify code from here to dispay an image instead of the color:我试图从这里修改代码以显示图像而不是颜色:

library(shiny)
library(shinydashboard)
ui <- dashboardPage(dashboardHeader(dropdownMenuOutput("notificationMenu")
                                    ), 
                    dashboardSidebar(sidebarMenu(id='sidebar',
                                                 menuItem("Page 1", tabName = "page1"),
                                                 menuItem("Page 2", tabName = "page2")
                                                 ),
                                     uiOutput('style_tag')
                                     ),
                    dashboardBody(
                      tabItems(
                        tabItem(tabName = "page1", h4("Picture!",style='color:black')),
                        tabItem(tabName = "page2", h4('white!')
                                )
                        )
                      )
                    )

server <- function(input, output, session){
  
  output$style_tag <- renderUI({
    if(input$sidebar=='page1')
      return(tags$head(tags$style(HTML('.content-wrapper {
                                             background-image:url("~/www/background.jpg") fixed center;
                                             }')
                                  )
                       )
             )
    
    if(input$sidebar=='page2')
      return(tags$head(tags$style(HTML('.content-wrapper {background-color:white;}')
                                  )
                       )
             )
  })
}

shinyApp(ui = ui, server = server)

However, it does not work.但是,它不起作用。 Am I doing something wrong in the CSS-bit?我在 CSS 位做错了吗? Is there any better ways of acheiving the same thing?有没有更好的方法来实现同样的事情?

Your path is from the perspective of your R working directory.您的路径是从 R 工作目录的角度来看的。 It needs to be from the perspective of the browser.它需要从浏览器的角度来看。 Change this CSS:更改此 CSS:

background-image:url("background.jpg")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM