Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 在R中添加CSS样式表_Html_Css_R_Shiny - Fatal编程技术网

Html 在R中添加CSS样式表

Html 在R中添加CSS样式表,html,css,r,shiny,Html,Css,R,Shiny,我正在制作我的第一个闪亮的应用程序,但在链接外部.css文件时遇到了问题。我看过一些教程和参考资料,其中有人解释了如何做,甚至展示了示例代码,但我运气不好。我看到的大多数示例都使用shinyUI或fluidPage函数,例如使用主题: shinyUI(fluidPage(theme = "bootstrap.css", headerPanel("New Application"), sidebarPanel( sliderInput("ob

我正在制作我的第一个闪亮的应用程序,但在链接外部.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"))
                )
       )
或者使用
标记$link

shinyUI(fluidPage(
       tags$head(
                tags$link(rel = "stylesheet", type = "text/css", href = "bootstrap.css")
                ),
       headerPanel("New Application")
                 )
       )
或使用
includecs

我在没有shinyUI的情况下单独使用
fluidPage
,但所有选项都不起作用。我已经确认我的工作目录和应用程序目录是我认为它们应该在的地方,并且包含保存.css文件的“www”子目录。唯一有效的方法是在我的
标记$head
中添加
标记$style
和HTML,如下所示:

fluidPage(
         tags$head(
             tags$style(
                       HTML(
                           "h1 {color:purple;}
                           .blue-item {color:blue;}
                           #dark {color:navy;}"
                            )
                       )
                   )
         )
但这并不能解决问题,因为我没有用这个命令链接CSS样式表,因此我不会更改我的应用程序的外观

To get CSS into your Shiny App, you 

Add style sheets with the www directory
Add CSS to your HTML header
Add styling directly to HTML tags
链接到样式表文件

<!DOCTYPE html>
<html>
  <head>
    <link type="text/css" rel="stylesheet" href="bootstrap.css"/>
  </head>
  <body>
  </body>
</html>

来自@esteban:


我已经解决了这个问题,我将文件重命名为
app.R
,而不是
.R
,RStudio以不同的方式识别它,并能够加载.css文件。我发现的另一种选择是使用
install.packages(“shinythemes”)
安装R-package
shinythemes
,并在
fluidPage
中定义主题,如下所示:

fluidPage(
    theme = shinytheme("cerulean"),
    ### UI CODE HERE ###
)

文章可能对您感兴趣。请检查您的
bootstrap.css
。我下载了一个,它并没有改变用户界面的默认值,即使它是正确的。更改一些,例如,
body{background color;}
,与官方教程不同,我的是
#fff
。在编辑css后,更改实际上已经存在。我已经解决了这个问题,我将文件重命名为app.R而不是.R,RStudio以不同的方式识别它,并能够加载.css文件。我发现的另一种选择是使用install.packages(“shinythemes”)安装R包'shinythemes',并在fluidPage中定义主题如下:fluidPage(theme=shinytheme(“cerulean”),tabsetPanel())将问题标记为已回答。