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

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

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

问题

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

这里有一个小例子:

library(shiny)

shinyApp(
  ui = fluidPage(
    selectInput("Input", 
                label = tags$span(
                  "Input", 
                  tags$i(
                    class = "glyphicon glyphicon-info-sign",
                    style = "color: black",
                    title = "hover text"
                  ),
                ),
                choices = c("a","b")),
    ),
  
  server = function(input, output) {}
)

希望这能帮助你。

英文:

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:

library(shiny)

shinyApp(
  ui = fluidPage(
    selectInput("Input", 
                label = tags$span(
                  "Input", 
                  tags$i(
                    class = "glyphicon glyphicon-info-sign",
                    style = "color: black",
                    title = "hover text"
                  ),
                ),
                choices = c("a","b")),
    ),
  
  server = function(input, output) {}
)

答案1

得分: 1

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

library(shiny)

shinyApp(
    ui = fluidPage(
        tags$head(tags$style(
            HTML(
                "
      #info-sign {
      margin-left:40px;
      margin-top:3px;
      position: absolute;
      }

      #info-sign .text {
      position:absolute;
      bottom:-5px;
      left:20px;
      visibility:hidden;
      font-weight:bolder;
      }

      #info-sign:hover .text {
      visibility:visible;
      color:red;
      }
            "
            )
        )),
        
        selectInput(
            "Input",
            label = tags$span("Input"),
            choices = c("a", "b")
        ),
        
        # HTML for the info sign
        tags$div(
            id = 'info-sign',
            class = "glyphicon glyphicon-info-sign",
            tags$span(class = "text", tags$p("formatted"))
        )
    ),
    
    server = function(input, output) {
        
    }
)

如何更改由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生成的悬停文本的样式?

library(shiny)

shinyApp(
    ui = fluidPage(
        tags$head(tags$style(
            HTML(
                "
      #info-sign {
      margin-left:40px;
      margin-top:3px;
      position: absolute;
      }

      #info-sign .text {
      position:absolute;
      bottom:-5px;
      left:20px;
      visibility:hidden;
      font-weight:bolder;
      }

      #info-sign:hover .text {
      visibility:visible;
      color:red;
      }
      "
            )
        )),
        
        selectInput(
            "Input",
            label = tags$span("Input"),
            choices = c("a", "b")
        ),
        
        # HTML for the info sign
        tags$div(
            id = 'info-sign',
            class = "glyphicon glyphicon-info-sign",
            tags$span(class = "text", tags$p("formatted"))
        )
    ),
    
    server = function(input, output) {
        
    }
)

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:

确定