【问题标题】:Hovering on icon should display text悬停在图标上应显示文本
【发布时间】:2022-01-17 12:08:47
【问题描述】:

有没有办法在“国家”旁边添加一个图标,当用户将鼠标悬停在它上面时,它应该显示一些文字

library(shiny)

ui <- fluidPage(
  selectInput("Sel","Sel",choices = 1:100),
  htmlOutput("Sd")
)

server <- function(input, output, session) {
  output$Sd <- renderUI({
    "Country"
  })
}

shinyApp(ui, server)

【问题讨论】:

    标签: shiny


    【解决方案1】:

    带有一点 HTML 和 CSS 然后你可以使用 CSS 自定义悬停文本

    library(shiny)
    
    ui <- fluidPage(
      
    # Add CSS
      tags$head(
        tags$style(HTML("
          #an_icon .text {
          position:relative;
          bottom:30px;
          left:0px;
          visibility:hidden;
          }
    
          #an_icon:hover .text {
          visibility:visible;
          }
          "))
      ),
      
      selectInput("Sel","Sel",choices = 1:100),
      htmlOutput("Sd"),
    
    # HTML for the icon
      tags$div(id = 'an_icon', 
               icon("bar-chart"),
               tags$span(class = "text", tags$p("text")))
    )
    
    server <- function(input, output, session) {
      output$Sd <- renderUI({
        "Country"
      })
    }
    
    shinyApp(ui, server)
    

    【讨论】:

    【解决方案2】:
    library(shiny)
    library(shinyBS)
    
    ui <- fluidPage(
      selectInput("Sel","Sel",choices = 1:100),
      htmlOutput("Sd")
    )
    
    server <- function(input, output, session) {
      output$Sd <- renderUI({
        tags$span(
          "Country ", 
          tipify(
            icon("bar-chart"),
            "Hello, I am the tooltip!"
          )
        )
      })
    }
    
    shinyApp(ui, server)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-11
      • 1970-01-01
      • 1970-01-01
      • 2017-07-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多