r - 闪亮仪表板选项卡上的不同背景
问题描述
我想创建一个闪亮的仪表板,其中第一个选项卡的背景包含一张图片,存储在本地,其余选项卡包含纯白色背景。
我试图从这里修改代码以显示图像而不是颜色:
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")
推荐阅读
- r - 在附属机构中查找城市名称,并将它们与其对应的国家/地区添加到数据框的新列中
- php - 如何以仅执行权限运行 PHP 脚本
- go - 在 Go 结构中打印 *big.Int 字段的值
- mongodb - MongoDB - 历史会话中的多个分组
- python - 将文件从父目录导入 __main__
- bootstrap-4 - 日期选择器工具提示 HTML 未在 changeMonth 上触发 - 引导
- haskell - 如何从 TemplateHaskell 引用函数
- ios - IPA 文件中的哪些文件已签名?
- git - Sourcetree - 由于提交消息为空而中止提交,所有编辑器都不起作用
- boost - Tlsv1 警报内部错误。与 IBM 握手期间的 Libboost 1.60.0