如何更改由tags$i生成的悬停文本的样式?

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

How to change the style of the hover text generated by tags$i?

问题

我正在寻找一种改变由 tags$i 生成的悬停文本(如字体、背景颜色等)布局的方法。样式参数仅适用于生成的图标,而不适用于悬停时出现的标题。我发现使用 shinyBS 有几种选项,但不幸的是,我受限于使用 tags$i

这里有一个小例子:

  1. library(shiny)
  2. shinyApp(
  3. ui = fluidPage(
  4. selectInput("Input",
  5. label = tags$span(
  6. "Input",
  7. tags$i(
  8. class = "glyphicon glyphicon-info-sign",
  9. style = "color: black",
  10. title = "hover text"
  11. ),
  12. ),
  13. choices = c("a","b")),
  14. ),
  15. server = function(input, output) {}
  16. )

希望这能帮助你。

英文:

I am looking for a way to change the layout (such as font, background colour, etc.) of the hover text ("title") generated by tags$i. The style argument applies only to the icon generated, not the title appearing upon hover. I found several options using shinyBS but, unfortunately, I am restricted to tags$i.

Here's a small example:

  1. library(shiny)
  2. shinyApp(
  3. ui = fluidPage(
  4. selectInput("Input",
  5. label = tags$span(
  6. "Input",
  7. tags$i(
  8. class = "glyphicon glyphicon-info-sign",
  9. style = "color: black",
  10. title = "hover text"
  11. ),
  12. ),
  13. choices = c("a","b")),
  14. ),
  15. server = function(input, output) {}
  16. )

答案1

得分: 1

这是一种不使用shinyBS的可能性:将信息标志添加为单独的div,并分别添加相应的HTMLCSS。然后,您可以在悬停在信息标志上时完全自定义显示的文本。

  1. library(shiny)
  2. shinyApp(
  3. ui = fluidPage(
  4. tags$head(tags$style(
  5. HTML(
  6. "
  7. #info-sign {
  8. margin-left:40px;
  9. margin-top:3px;
  10. position: absolute;
  11. }
  12. #info-sign .text {
  13. position:absolute;
  14. bottom:-5px;
  15. left:20px;
  16. visibility:hidden;
  17. font-weight:bolder;
  18. }
  19. #info-sign:hover .text {
  20. visibility:visible;
  21. color:red;
  22. }
  23. "
  24. )
  25. )),
  26. selectInput(
  27. "Input",
  28. label = tags$span("Input"),
  29. choices = c("a", "b")
  30. ),
  31. # HTML for the info sign
  32. tags$div(
  33. id = 'info-sign',
  34. class = "glyphicon glyphicon-info-sign",
  35. tags$span(class = "text", tags$p("formatted"))
  36. )
  37. ),
  38. server = function(input, output) {
  39. }
  40. )

如何更改由tags$i生成的悬停文本的样式?

英文:

Here is a possibility without using shinyBS: Add the info sign as a separate div and add the corresponding HTML and CSS separately. Then you can fully customise the displayed text when hovering the info sign.

如何更改由tags$i生成的悬停文本的样式?

  1. library(shiny)
  2. shinyApp(
  3. ui = fluidPage(
  4. tags$head(tags$style(
  5. HTML(
  6. "
  7. #info-sign {
  8. margin-left:40px;
  9. margin-top:3px;
  10. position: absolute;
  11. }
  12. #info-sign .text {
  13. position:absolute;
  14. bottom:-5px;
  15. left:20px;
  16. visibility:hidden;
  17. font-weight:bolder;
  18. }
  19. #info-sign:hover .text {
  20. visibility:visible;
  21. color:red;
  22. }
  23. "
  24. )
  25. )),
  26. selectInput(
  27. "Input",
  28. label = tags$span("Input"),
  29. choices = c("a", "b")
  30. ),
  31. # HTML for the info sign
  32. tags$div(
  33. id = 'info-sign',
  34. class = "glyphicon glyphicon-info-sign",
  35. tags$span(class = "text", tags$p("formatted"))
  36. )
  37. ),
  38. server = function(input, output) {
  39. }
  40. )

huangapple
  • 本文由 发表于 2023年7月13日 20:05:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/76679188.html
匿名

发表评论

匿名网友

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

确定