[英]R shiny - background of sidebar panel
让我们说,我有一个简单的闪亮应用程序,我想改变侧边栏面板背景 。 我试过用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';
}
尝试这个:
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,并为此表单的背景着色。
如果我能找到它,这在某处有答案。 (我知道,因为当我想改变侧边栏的背景颜色时,我找到了答案)。 您可以使用tags$style()
函数来获取所需内容。 我不记得你是否想要为身体或井上的颜色做好准备(显然我都做了),但你可以稍微玩一下,直到得到你的结果。
sidebarPanel(
tags$style(".well {background-color:[your_color];}"),
...)
事实证明你只想改变.well
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.