代码之家  ›  专栏  ›  技术社区  ›  M.Qasim

如何在闪亮的仪表板中向html小部件添加工具提示

  •  1
  • M.Qasim  · 技术社区  · 6 年前

    我正在努力为Rshiny中的html小部件添加工具提示。 bs_embed_tooltip 从…起 library(flexdashboard) 对一些闪亮的小部件执行此操作,但在将其应用于html小部件时返回以下错误:

    Error in .tag_validate(.) : 
      tag is not a shiny.tag - tag must be generated using htmltools or shiny
    

    下面是我的最小工作示例(修改shinydashboard中的示例代码):

    ## app.R ##
    library(shinydashboard)
    library(flexdashboard)
    library(bsplus) # For shiny tooltips
    
    ui <- dashboardPage(
      dashboardHeader(title = "Basic dashboard"),
      dashboardSidebar(),
      dashboardBody(
        # Boxes need to be put in a row (or column)
        fluidRow(
          box(plotOutput("plot1", height = 250) %>%
                bs_embed_tooltip("This is the output chart.", placement = 'bottom')
          ),
    
          box(title = "Controls",
              sliderInput("slider", "Number of observations:", 1, 100, 50) %>%
                bs_embed_tooltip("Use this slider to select the number of observations.", placement = 'bottom')
          ),
          box(title = "Guage",
              gaugeOutput("guage_value") # %>% bs_embed_tooltip("This gauge shows the input value from the slider.", placement = 'bottom')
          )
        )
      )
    )
    
    server <- function(input, output) {
      set.seed(122)
      histdata <- rnorm(500)
    
      output$plot1 <- renderPlot({
        data <- histdata[seq_len(input$slider)]
        hist(data)
      })
    
      output$guage_value <- renderGauge({
    
        gauge(input$slider, min = 0, max = 100, symbol = '', gaugeSectors(
          danger = c(0, 30), warning = c(31, 70), success = c(71, 100) ))
    
      })
    }
    
    shinyApp(ui, server)
    

    如果您能在评论中帮助理解代码,我们将不胜感激。

    1 回复  |  直到 6 年前
        1
  •  1
  •   SeGa    6 年前

    尝试使用此新的仪表箱:

      box(title = "Guage",
          gaugeOutput("guage_value"),
          bsTooltip(id = "guage_value", title = "This gauge shows the input value from the slider.", placement = "bottom")
      )