【发布时间】:2015-10-24 20:31:28
【问题描述】:
我正在制作我的第一个闪亮的应用程序,但在链接外部 .css 文件时遇到问题。我看过一些教程和参考资料,人们解释了如何做,甚至展示了示例代码,但我没有任何运气。我见过的大多数示例都使用了 shinyUI 或 fluidPage 函数,例如使用主题:
shinyUI(fluidPage(theme = "bootstrap.css",
headerPanel("New Application"),
sidebarPanel(
sliderInput("obs", "Number of observations:",
min = 1, max = 1000, value = 500)
),
mainPanel(plotOutput("distPlot"))
)
)
或者这个使用tags$link:
shinyUI(fluidPage(
tags$head(
tags$link(rel = "stylesheet", type = "text/css", href = "bootstrap.css")
),
headerPanel("New Application")
)
)
或使用includeCSS
我单独使用fluidPage,没有shinyUI,但没有一个选项有效。我已经确认我的工作目录和 app-Directory 是我认为应该在的位置,并且包含保存 .css 文件的“www”子目录。唯一可行的是,如果我在我的tags$head 中添加一个tags$style 和一个HTML,如下所示:
fluidPage(
tags$head(
tags$style(
HTML(
"h1 {color:purple;}
.blue-item {color:blue;}
#dark {color:navy;}"
)
)
)
)
但这并没有解决问题,因为我没有用这个命令链接 CSS 样式表,因此我没有改变我的应用程序的外观。
【问题讨论】:
-
This 文章可能对您感兴趣。
-
检查您的
bootstrap.css。我下载了一个,它并没有改变 UI 默认值,即使它被正确加载。改变一些,例如body{background-color;},我的是#fff,不像官方教程。编辑 css 后,更改实际上就在那里。 -
我已经解决了这个问题,我将文件重命名为 app.R 而不是
.R 并且 RStudio 以不同的方式识别它并且能够加载 .css 文件。我发现的另一种选择是使用 install.packages("shinythemes") 安装 R-package 'shinythemes',并在 fluidPage 中定义主题如下:fluidPage(theme = shinytheme("cerulean"), tabsetPanel())