【问题标题】:R shiny - background of sidebar panelR 闪亮 - 侧边栏面板的背景
【发布时间】:2016-02-26 18:12:34
【问题描述】:

假设我有一个简单的闪亮应用程序,我想更改侧边栏面板背景。我已经尝试过使用 css,但我只设法改变了整个背景。你能帮帮我吗?

我的 ui.R:

    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';
    }

【问题讨论】:

    标签: css r user-interface server shiny


    【解决方案1】:

    如果我能找到,这在某处有答案。 (我知道是因为当我想更改侧边栏的背景颜色时找到了答案)。您可以使用tags$style() 函数来获取您需要的内容。我不记得你是想给身体上色还是井上色,(显然我都做了),但你可以尝试一下,直到你得到你的结果。

    sidebarPanel(
      tags$style(".well {background-color:[your_color];}"),
      ...)
    

    原来你只想更改.well

    【讨论】:

    【解决方案2】:

    试试这个:

    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 和一些逻辑来确定哪个是要着色的属性列(这样我们只设置背景侧边栏),或者您可以为嵌套在列中的表单提供一个 id 并为该表单的背景着色。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-23
      • 1970-01-01
      • 2020-09-20
      • 2019-11-13
      • 1970-01-01
      • 1970-01-01
      • 2016-11-11
      • 2018-06-02
      相关资源
      最近更新 更多