如何在 Shiny 应用中悬停在 navbarPage 链接上时更改文本颜色?

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

How to change text colour of navbarPage links when hovered on (in shiny app)?

问题

这是我的闪亮应用的经过编辑的版本:

  1. ui <- tagList(
  2. fluidPage(
  3. titlePanel(""),
  4. tags$head(tags$style(HTML(
  5. "
  6. .navbar-default {
  7. color: red !important;'
  8. }
  9. "
  10. ))),
  11. navbarPage(
  12. windowTitle = "应用名称",
  13. theme = bs_theme(bootswatch = "flatly",
  14. base_font = font_google("Lato"),
  15. primary = "#333F50",
  16. bg = "white",
  17. fg = "#D67540"),
  18. title = "我是标题",
  19. selected = "主选项卡 1",
  20. tabPanel(title = "主选项卡 1",
  21. fluidPage(
  22. sidebarLayout(
  23. sidebarPanel(textInput(inputId = "text_input", label = "输入文本:")),
  24. mainPanel(textOutput(outputId = "text_output"))
  25. )
  26. )
  27. ),
  28. tabPanel(title = "主选项卡 2",
  29. fluidPage(
  30. fluidRow(
  31. column(7,
  32. navlistPanel(
  33. tabPanel("选项卡 1"),
  34. tabPanel("选项卡 2"),
  35. tabPanel("选项卡 3"),
  36. widths = c(2, 10),
  37. well = FALSE)
  38. )))
  39. )
  40. )
  41. )
  42. )
  43. server <- function(input, output){
  44. output$text_output <- renderText(input$text_input)
  45. }
  46. shinyApp(ui, server)

这是"主选项卡 1"的外观:
如何在 Shiny 应用中悬停在 navbarPage 链接上时更改文本颜色?

我想将"主选项卡 1"和"主选项卡 2"的文本颜色从白色更改为粉红色,链接在悬停/选择时从水鸭绿色更改为红色。

到目前为止,我尝试了许多以下代码的变化,但没有成功:

  1. .navbar-default {
  2. color: red !important;
  3. }

有人知道如何修复这个问题吗?

非常感谢任何帮助 如何在 Shiny 应用中悬停在 navbarPage 链接上时更改文本颜色?

英文:

Here is the a redacted version of my shiny app:

  1. ui <- tagList(
  2. fluidPage(
  3. titlePanel(""),
  4. tags$head(tags$style(HTML(
  5. "
  6. .navbar-default {
  7. color: red !important;'
  8. }
  9. "
  10. ))),
  11. navbarPage(
  12. windowTitle = "App Name",
  13. theme = bs_theme(bootswatch = "flatly",
  14. base_font = font_google("Lato"),
  15. primary = "#333F50",
  16. bg = "white",
  17. fg = "#D67540"),
  18. title = "I am the title",
  19. selected = "Main Tab 1",
  20. tabPanel(title = "Main Tab 1",
  21. fluidPage(
  22. sidebarLayout(
  23. sidebarPanel(textInput(inputId = "text_input", label = "Enter text:")),
  24. mainPanel(textOutput(outputId = "text_output"))
  25. )
  26. )
  27. ),
  28. tabPanel(title = "Main Tab 2",
  29. fluidPage(
  30. fluidRow(
  31. column(7,
  32. navlistPanel(
  33. tabPanel("Tab 1"),
  34. tabPanel("Tab 2"),
  35. tabPanel("Tab 3"),
  36. widths = c(2, 10),
  37. well = FALSE)
  38. )))
  39. )
  40. )
  41. )
  42. )
  43. server <- function(input, output){
  44. output$text_output <- renderText(input$text_input)
  45. }
  46. shinyApp(ui, server)

This is what "Main Tab 1" looks like:
如何在 Shiny 应用中悬停在 navbarPage 链接上时更改文本颜色?

I would like to change the text colour of "Main Tab 1" and "Main Tab 2" from white to pink, and from teal green to red when the links are hovered/selected.

So far I've tried many variations of the following but without success:

  1. .navbar-default {
  2. color: red !important;
  3. }

Does anyone know how to fix this?

Any help is much appreciated 如何在 Shiny 应用中悬停在 navbarPage 链接上时更改文本颜色?

答案1

得分: 1

我们可以使用以下CSS代码块来实现:

  1. library(bslib)
  2. library(shiny)
  3. ui <- tagList(
  4. fluidPage(
  5. titlePanel(""),
  6. tags$head(tags$style(HTML(
  7. "
  8. .navbar-default {
  9. color: red !important;'
  10. }
  11. .navbar-default .navbar-nav > .active > a,
  12. .navbar-default .navbar-nav > li > a:hover {
  13. color: red !important;
  14. }
  15. .navbar-default .navbar-nav > li > a {
  16. color: pink !important;
  17. }
  18. "
  19. ))),
  20. navbarPage(
  21. windowTitle = "App Name",
  22. theme = bs_theme(bootswatch = "flatly",
  23. base_font = font_google("Lato"),
  24. primary = "#333F50",
  25. bg = "white",
  26. fg = "#D67540"),
  27. title = "I am the title",
  28. selected = "Main Tab 1",
  29. tabPanel(title = "Main Tab 1",
  30. fluidPage(
  31. sidebarLayout(
  32. sidebarPanel(textInput(inputId = "text_input", label = "Enter text:")),
  33. mainPanel(textOutput(outputId = "text_output"))
  34. )
  35. )
  36. ),
  37. tabPanel(title = "Main Tab 2",
  38. fluidPage(
  39. fluidRow(
  40. column(7,
  41. navlistPanel(
  42. tabPanel("Tab 1"),
  43. tabPanel("Tab 2"),
  44. tabPanel("Tab 3"),
  45. widths = c(2, 10),
  46. well = FALSE)
  47. )))
  48. )
  49. )
  50. )
  51. )
  52. server <- function(input, output){
  53. output$text_output <- renderText(input$text_input)
  54. }
  55. shinyApp(ui, server)

如何在 Shiny 应用中悬停在 navbarPage 链接上时更改文本颜色?

英文:

We can do it with the following CSS code block:

  1. library(bslib)
  2. library(shiny)
  3. ui <- tagList(
  4. fluidPage(
  5. titlePanel(""),
  6. tags$head(tags$style(HTML(
  7. "
  8. .navbar-default {
  9. color: red !important;'
  10. }
  11. .navbar-default .navbar-nav > .active > a,
  12. .navbar-default .navbar-nav > li > a:hover {
  13. color: red !important;
  14. }
  15. .navbar-default .navbar-nav > li > a {
  16. color: pink !important;
  17. }
  18. "
  19. ))),
  20. navbarPage(
  21. windowTitle = "App Name",
  22. theme = bs_theme(bootswatch = "flatly",
  23. base_font = font_google("Lato"),
  24. primary = "#333F50",
  25. bg = "white",
  26. fg = "#D67540"),
  27. title = "I am the title",
  28. selected = "Main Tab 1",
  29. tabPanel(title = "Main Tab 1",
  30. fluidPage(
  31. sidebarLayout(
  32. sidebarPanel(textInput(inputId = "text_input", label = "Enter text:")),
  33. mainPanel(textOutput(outputId = "text_output"))
  34. )
  35. )
  36. ),
  37. tabPanel(title = "Main Tab 2",
  38. fluidPage(
  39. fluidRow(
  40. column(7,
  41. navlistPanel(
  42. tabPanel("Tab 1"),
  43. tabPanel("Tab 2"),
  44. tabPanel("Tab 3"),
  45. widths = c(2, 10),
  46. well = FALSE)
  47. )))
  48. )
  49. )
  50. )
  51. )
  52. server <- function(input, output){
  53. output$text_output <- renderText(input$text_input)
  54. }
  55. shinyApp(ui, server)

如何在 Shiny 应用中悬停在 navbarPage 链接上时更改文本颜色?

huangapple
  • 本文由 发表于 2023年2月18日 02:42:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/75488188.html
匿名

发表评论

匿名网友

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

确定