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

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

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

问题

在R Shiny App中使用shinythemes覆盖按钮的背景颜色,我尝试了很多小时的CSS,但没有成功,非常感谢任何人能够帮助。

以下是我尝试的示例代码,它只在按钮被按下时更改颜色,但我想要颜色保持"永久":

  1. library(shiny)
  2. library(shinythemes)
  3. shinyApp(
  4. ui =
  5. navbarPage(id = "intabset",
  6. title = "HOME",
  7. windowTitle = "Data cleaning",
  8. theme = shinytheme("cerulean"),
  9. collapsible = TRUE,
  10. header=tags$style(
  11. "#actButt{
  12. background-color:red !important;
  13. color: black;
  14. -webkit-box-shadow: 0px;
  15. box-shadow: 0px;
  16. border:0px;
  17. }
  18. #dwdButt{
  19. background-color:green !important;
  20. color: black;
  21. -webkit-box-shadow: 0px;
  22. box-shadow: 0px;
  23. border:0px;
  24. }"),
  25. tabPanel(
  26. title = " Home", icon = icon("home"),
  27. mainPanel(width = 11, style="margin-left:4%; margin-right:4%",
  28. fluidRow(h3("Home page data cleaning")),
  29. downloadButton('dwdButt', 'Download data'),
  30. actionButton('actButt', 'Generate data'),
  31. actionButton('actButt2', 'Generate data 2',
  32. style = "background-color: red !important; color: black")
  33. )
  34. )# end tabpanel
  35. ), # end navbarpage
  36. server = function(input, output) {
  37. }
  38. )

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

英文:

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''

  1. library(shiny)
  2. library(shinythemes)
  3. shinyApp(
  4. ui =
  5. navbarPage(id = "intabset",
  6. title = "HOME",
  7. windowTitle = "Data cleaning",
  8. theme = shinytheme("cerulean"),
  9. collapsible = TRUE,
  10. header=tags$style(
  11. "#actButt{
  12. background-color:red !important;
  13. color: black;
  14. -webkit-box-shadow: 0px;
  15. box-shadow: 0px;
  16. border:0px;
  17. }
  18. #dwdButt{
  19. background-color:green !important;
  20. color: black;
  21. -webkit-box-shadow: 0px;
  22. box-shadow: 0px;
  23. border:0px;
  24. }"),
  25. tabPanel(
  26. title = " Home", icon = icon("home"),
  27. mainPanel(width = 11, style="margin-left:4%; margin-right:4%",
  28. fluidRow(h3("Home page data cleaning")),
  29. downloadButton('dwdButt',
  30. 'Download data'),
  31. actionButton('actButt',
  32. 'Generate data'),
  33. actionButton('actButt2',
  34. 'Generate data 2',
  35. style = "background-color: red !important; color: black")
  36. )
  37. )# end tabpanel
  38. ), # end navbarpage
  39. server = function(input, output) {
  40. }
  41. )

NB : I have seen this answer, but it does not help.

答案1

得分: 2

For one button id:

  1. library(shiny)
  2. library(shinythemes)
  3. shinyApp(
  4. ui =
  5. navbarPage(id = "intabset",
  6. title = "HOME",
  7. windowTitle = "Data cleaning",
  8. theme = shinytheme("cerulean"),
  9. collapsible = TRUE,
  10. header=tags$style(
  11. "#actButt{
  12. background-image: none;
  13. background-color:red !important;
  14. color: black;
  15. -webkit-box-shadow: 0px;
  16. box-shadow: 0px;
  17. border:0px;
  18. }
  19. #dwdButt{
  20. background-color:green !important;
  21. color: black;
  22. -webkit-box-shadow: 0px;
  23. box-shadow: 0px;
  24. border:0px;
  25. }"),
  26. tabPanel(
  27. title = " Home", icon = icon("home"),
  28. mainPanel(width = 11, style="margin-left:4%; margin-right:4%",
  29. fluidRow(h3("Home page data cleaning")),
  30. downloadButton('dwdButt', 'Download data'),
  31. actionButton('actButt', 'Generate data'),
  32. actionButton('actButt2', 'Generate data 2',
  33. style = "background-color: red !important; color: black")
  34. )
  35. )# end tabpanel
  36. ), # end navbarpage
  37. server = function(input, output) {
  38. }
  39. )

For all buttons:

  1. library(shiny)
  2. library(shinythemes)
  3. shinyApp(
  4. ui =
  5. navbarPage(id = "intabset",
  6. title = "HOME",
  7. windowTitle = "Data cleaning",
  8. theme = shinytheme("cerulean"),
  9. collapsible = TRUE,
  10. header=tags$style(
  11. ".btn-default{
  12. background-image: none;
  13. }
  14. #actButt{
  15. background-color:red !important;
  16. color: black;
  17. -webkit-box-shadow: 0px;
  18. box-shadow: 0px;
  19. border:0px;
  20. }
  21. #dwdButt{
  22. background-color:green !important;
  23. color: black;
  24. -webkit-box-shadow: 0px;
  25. box-shadow: 0px;
  26. border:0px;
  27. }"),
  28. tabPanel(
  29. title = " Home", icon = icon("home"),
  30. mainPanel(width = 11, style="margin-left:4%; margin-right:4%",
  31. fluidRow(h3("Home page data cleaning")),
  32. downloadButton('dwdButt', 'Download data'),
  33. actionButton('actButt', 'Generate data'),
  34. actionButton('actButt2', 'Generate data 2',
  35. style = "background-color: red !important; color: black")
  36. )
  37. )# end tabpanel
  38. ), # end navbarpage
  39. server = function(input, output) {
  40. }
  41. )
英文:

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

For one button id:

  1. library(shiny)
  2. library(shinythemes)
  3. shinyApp(
  4. ui =
  5. navbarPage(id = "intabset",
  6. title = "HOME",
  7. windowTitle = "Data cleaning",
  8. theme = shinytheme("cerulean"),
  9. collapsible = TRUE,
  10. header=tags$style(
  11. "#actButt{
  12. background-image: none;
  13. background-color:red !important;
  14. color: black;
  15. -webkit-box-shadow: 0px;
  16. box-shadow: 0px;
  17. border:0px;
  18. }
  19. #dwdButt{
  20. background-color:green !important;
  21. color: black;
  22. -webkit-box-shadow: 0px;
  23. box-shadow: 0px;
  24. border:0px;
  25. }"),
  26. tabPanel(
  27. title = " Home", icon = icon("home"),
  28. mainPanel(width = 11, style="margin-left:4%; margin-right:4%",
  29. fluidRow(h3("Home page data cleaning")),
  30. downloadButton('dwdButt',
  31. 'Download data'),
  32. actionButton('actButt',
  33. 'Generate data'),
  34. actionButton('actButt2',
  35. 'Generate data 2',
  36. style = "background-color: red !important; color: black")
  37. )
  38. )# end tabpanel
  39. ), # end navbarpage
  40. server = function(input, output) {
  41. }
  42. )

For all buttons:

  1. library(shiny)
  2. library(shinythemes)
  3. shinyApp(
  4. ui =
  5. navbarPage(id = "intabset",
  6. title = "HOME",
  7. windowTitle = "Data cleaning",
  8. theme = shinytheme("cerulean"),
  9. collapsible = TRUE,
  10. header=tags$style(
  11. ".btn-default{
  12. background-image: none;
  13. }
  14. #actButt{
  15. background-color:red !important;
  16. color: black;
  17. -webkit-box-shadow: 0px;
  18. box-shadow: 0px;
  19. border:0px;
  20. }
  21. #dwdButt{
  22. background-color:green !important;
  23. color: black;
  24. -webkit-box-shadow: 0px;
  25. box-shadow: 0px;
  26. border:0px;
  27. }"),
  28. tabPanel(
  29. title = " Home", icon = icon("home"),
  30. mainPanel(width = 11, style="margin-left:4%; margin-right:4%",
  31. fluidRow(h3("Home page data cleaning")),
  32. downloadButton('dwdButt',
  33. 'Download data'),
  34. actionButton('actButt',
  35. 'Generate data'),
  36. actionButton('actButt2',
  37. 'Generate data 2',
  38. style = "background-color: red !important; color: black")
  39. )
  40. )# end tabpanel
  41. ), # end navbarpage
  42. server = function(input, output) {
  43. }
  44. )

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:

确定