R 闪亮 - 侧边栏面板的背景 [英] R shiny - background of sidebar panel

查看:22
本文介绍了R 闪亮 - 侧边栏面板的背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Let's say, I've got a simple shiny application and I would like to change sidebar panel background. I've tried with css, but I've managed only to change the whole background. Can you help me?

我的 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")
        )
      )
    ))

和我的 server.R:

and my server.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:

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

The sidebar doesn't have any other attributs than 'col-sm-4' when initialized so you can either use jQuery and some logic to figure out which is the propper column to color (so that we only set the background of the sidebar), or you can give a id to the form nested in the column and color the background of this form.

这篇关于R 闪亮 - 侧边栏面板的背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆