![](/img/trans.png)
[英]renderDataTable with actionButton in two shinydashboard tabs
[英]Different backgrounds on shinydashboard tabs
我想创建一个闪亮的仪表板,其中第一个选项卡的背景包含本地存储的图片,其余选项卡包含纯白色背景。
我试图从这里修改代码以显示图像而不是颜色:
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)
但是,它不起作用。 我在 CSS 位做错了吗? 有没有更好的方法来实现同样的事情?
您的路径是从 R 工作目录的角度来看的。 它需要从浏览器的角度来看。 更改此 CSS:
background-image:url("background.jpg")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.