R Shiny App:在使用shinytheme时覆盖按钮背景颜色

huangapple go评论65阅读模式
英文:

R Shiny App : override button background color while using a shinytheme

问题

在R Shiny App中使用shinythemes覆盖按钮的背景颜色,我尝试了很多小时的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) {
  }
)

注意:我看过这个答案,但没有帮助。

英文:

Does anyone know how I can override background color of buttons in a R Shiny App while using shinythemes ?

I have tried tons of css since hours without success... I am getting crazy... I would be very grateful if anyone could help.

Here below an example of what I tried : it colors only the button when it is pressed, but I would like to have the colour ''permanently''

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 : I have seen this answer, but it does not help.

答案1

得分: 2

For one button 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) {
  }
)

For all buttons:


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) {
  }
)
英文:

You need to set background-image: none; either for a single button id or for the whole class.

For one button 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) {
  }
)

For all buttons:


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) {
  }
)

huangapple
  • 本文由 发表于 2023年2月27日 19:20:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/75579803.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定