addTooltip with dynamic title

623 Views Asked by At

I have a shiny app with an input slider and an output table. I want to put a tooltip over the output table with text that includes the input from the input slider, i.e. the tooltip text updates dynamically with the change in the slider. I cannot get it to work.

library(shiny)
library(shinyBS)


ui <- fluidPage(
  sliderInput(inputId="inputValue",label="Input Value", 0,100, value=90, step=1),

  tableOutput(outputId="outputTableId")
)


server <- function(input, output, session) {
  renderTables <- observe({
    browser()
    output$outputTableId<-renderTable({
      data.frame("Output" = c(1,2,3) * input$inputValue)  
    })
    addTooltip(session, id="outputTableId", title=paste0("Tooltip text with dynamic ",input$inputValue,"% prediction interval"), placement="right")

  })


}

shinyApp(ui = ui, server = server)

In my main app (too big to post here), the tooltip was working and updating, but only every other update - on every other change of slider, the tooltip wouldn't show up at all, but the other times it would work, with the correct dynamic value. This may be related to this question, which is possibly a bug.

However when trying to create a reproducable example for this question, I cannot even get it to work at all.

1

There are 1 best solutions below

0
On

Hmm, not obvious. Here is the way I've found:

library(shiny)
library(shinyBS)

ui <- fluidPage(
  sliderInput(inputId="inputValue", label="Input Value", 0,100, value=90, step=1),
  div(
    id = "container",
    style = "display:inline-block",
    uiOutput("table")
  )
)


server <- function(input, output, session) {
  output$outputTableId <- renderTable({
    data.frame("Output" = c(1,2,3) * input$inputValue)  
  })

  output$table <- renderUI({
    tipify(
      tableOutput(outputId = "outputTableId"),
      title=paste0("Tooltip text with dynamic ", input$inputValue, "% prediction interval"),
      placement = "right",
      options = list(container = "#container"))
  })

}

shinyApp(ui = ui, server = server)