css R闪亮应用:使用shinytheme时覆盖按钮背景色

slmsl1lt  于 2023-03-05  发布在  其他
关注(0)|答案(1)|浏览(128)

有人知道我如何在使用shinythemes时覆盖R Shiny应用程序中按钮的背景色吗?
我已经尝试了吨的css,因为小时没有成功...我越来越疯狂...我会非常感激,如果任何人可以帮助。
下面是我尝试的一个例子:它只在按钮被按下时给按钮着色,但我希望颜色是“永久”的

library(shiny)
library(shinythemes)
shinyApp(
  ui = 
    navbarPage(id = "intabset", 
               title = "HOME",
               windowTitle = "Data cleaning", 
               theme = shinytheme("cerulean"), 
               collapsible = TRUE, 
               header=tags$style(
                 "#actButt{
     background-color:red !important;
      color: black;
      -webkit-box-shadow: 0px;
      box-shadow: 0px;
           border:0px;
                 }
    #dwdButt{
     background-color:green !important;
      color: black;
      -webkit-box-shadow: 0px;
      box-shadow: 0px;
           border:0px;
                 }"),
               tabPanel(
                 title = " Home", icon = icon("home"),
                 mainPanel(width = 11, style="margin-left:4%; margin-right:4%",
                           fluidRow(h3("Home page data cleaning")),
                           downloadButton('dwdButt',
                                          'Download data'),
                           actionButton('actButt',
                                          'Generate data'),
                             actionButton('actButt2',
                                        'Generate data 2',
                                        style = "background-color: red !important; color: black")
                           )
                 )# end tabpanel
    ), # end navbarpage
  server = function(input, output) {
  }
)

NB:我看过这个answer,但没有帮助。

bn31dyow

bn31dyow1#

您需要为单个按钮id或整个类设置background-image: none;
对于一个按钮ID:

library(shiny)
library(shinythemes)

shinyApp(
  ui = 
    navbarPage(id = "intabset", 
               title = "HOME",
               windowTitle = "Data cleaning", 
               theme = shinytheme("cerulean"), 
               collapsible = TRUE, 
               header=tags$style(
                 "#actButt{
    background-image: none;
     background-color:red !important;
      color: black;
      -webkit-box-shadow: 0px;
      box-shadow: 0px;
           border:0px;
                 }
    #dwdButt{
     background-color:green !important;
      color: black;
      -webkit-box-shadow: 0px;
      box-shadow: 0px;
           border:0px;
                 }"),
    tabPanel(
      title = " Home", icon = icon("home"),
      mainPanel(width = 11, style="margin-left:4%; margin-right:4%",
                fluidRow(h3("Home page data cleaning")),
                downloadButton('dwdButt',
                               'Download data'),
                actionButton('actButt',
                             'Generate data'),
                actionButton('actButt2',
                             'Generate data 2',
                             style = "background-color: red !important; color: black")
      )
    )# end tabpanel
    ), # end navbarpage
  server = function(input, output) {
  }
)

对于所有按钮:

library(shiny)
library(shinythemes)
shinyApp(
  ui = 
    navbarPage(id = "intabset", 
               title = "HOME",
               windowTitle = "Data cleaning", 
               theme = shinytheme("cerulean"), 
               collapsible = TRUE, 
               header=tags$style(
                 ".btn-default{
                 background-image: none;
                 }
                 
                 #actButt{
     background-color:red !important;
      color: black;
      -webkit-box-shadow: 0px;
      box-shadow: 0px;
           border:0px;
                 }
    #dwdButt{
     background-color:green !important;
      color: black;
      -webkit-box-shadow: 0px;
      box-shadow: 0px;
           border:0px;
                 }"),
    tabPanel(
      title = " Home", icon = icon("home"),
      mainPanel(width = 11, style="margin-left:4%; margin-right:4%",
                fluidRow(h3("Home page data cleaning")),
                downloadButton('dwdButt',
                               'Download data'),
                actionButton('actButt',
                             'Generate data'),
                actionButton('actButt2',
                             'Generate data 2',
                             style = "background-color: red !important; color: black")
      )
    )# end tabpanel
    ), # end navbarpage
  server = function(input, output) {
  }
)

相关问题