gpt4 book ai didi

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

转载 作者:技术小花猫 更新时间:2023-10-29 10:28:22 26 4
gpt4 key购买 nike

比方说,我有一个简单的 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com