css - R shiny - 侧边栏面板的背景

标签 css r user-interface server shiny

比方说,我有一个简单的 Shiny 应用程序,我想更改侧边栏面板背景。我试过使用 css,但我只设法改变了整个背景。你能帮帮我吗?

我的用户界面:

    library(shiny)

    shinyUI(fluidPage(
      includeCSS("www/moj_styl.css"),

      titlePanel("Hello Shiny!"),

      sidebarLayout(
       sidebarPanel(
          sliderInput("bins",
                      "Number of bins:",
                      min = 1,
                      max = 50,
                      value = 30)
        ),

        mainPanel(
          plotOutput("distPlot")
        )
      )
    ))

和我的服务器。R:

    library(shiny)

    shinyServer(function(input, output) {

      output$distPlot <- renderPlot({
        x    <- faithful[, 2]  # Old Faithful Geyser data
        bins <- seq(min(x), max(x), length.out = input$bins + 1)

        hist(x, breaks = bins, col = 'darkgray', border = 'white')
      })

    })

和 moj_styl.css:

    body {
        background-color: #dec4de;
    }

    body, label, input, button, select { 
      font-family: 'Arial';
    }

最佳答案

试试这个:

library(shiny)

ui <- shinyUI(fluidPage(
  tags$head(tags$style(
    HTML('
         #sidebar {
            background-color: #dec4de;
        }

        body, label, input, button, select { 
          font-family: "Arial";
        }')
  )),
  titlePanel("Hello Shiny!"),

  sidebarLayout(
    sidebarPanel(id="sidebar",
      sliderInput("bins",
                  "Number of bins:",
                  min = 1,
                  max = 50,
                  value = 30)
    ),

    mainPanel(
      plotOutput("distPlot")
    )
  )
))

server <- shinyServer(function(input, output) {

  output$distPlot <- renderPlot({
    x    <- faithful[, 2]  # Old Faithful Geyser data
    bins <- seq(min(x), max(x), length.out = input$bins + 1)

    hist(x, breaks = bins, col = 'darkgray', border = 'white')
  })

})

shinyApp(ui=ui,server=server)

侧边栏在初始化时除了“col-sm-4”之外没有任何其他属性,因此您可以使用 jQuery 和一些逻辑来确定哪个是要着色的 propper 列(这样我们只设置背景侧边栏),或者您可以为列中嵌套的表单指定一个 ID 并为该表单的背景着色。

关于css - R shiny - 侧边栏面板的背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33891362/

相关文章:

javascript - 允许滚动固定父元素的绝对子元素

javascript - 动态CSS类属性?

r - 使用方差分析测量回归系数贡献

r - 使用共享 y 轴在 1x4 网格中显示 R 图

c++ - Qt 文件夹浏览器多次打开

html - 如何水平和垂直居中div中的图像

javascript - 点亮元素 : best practise (or best performance) when creating many custom style rules vs a couple of dynamic rules inside a tiny web component?

r - 基于 R 中的查找表进行查找和替换,并将不匹配的保留原样

java - 使用 OnClickListener 删除适配器项

java - 在用户验证中按下登录按钮后,我的代码不显示任何内容