4

Is there a way to add popover or a tooltip to an

output$Text <- renderText({ c("TestText") }) element, which is then rendered through renderUI, using shinyBS?

vladli
  • 1,454
  • 2
  • 16
  • 40

2 Answers2

10

Something like this do?

Base Shiny

rm(list=ls())
library(shiny)

ui <- basicPage(
  headerPanel("Tooltip test"),
  mainPanel(
    column(3,tags$div(title="Tooltip works",verbatimTextOutput("Text")))
  )
)

server <- shinyServer(function(input, output,session) {
  
  output$Text <- renderText({ c("TestText") })
  
})
shinyApp(ui = ui, server = server)

enter image description here

ShinyBS

rm(list=ls())
library(shiny)
library(shinyBS)

ui <- basicPage(
  headerPanel("Tooltip test"),
  bsTooltip("Text", "Tooltip works", placement = "bottom", trigger = "hover",
            options = NULL),
  mainPanel(
    column(3,verbatimTextOutput("Text"))
  )
)

server <- shinyServer(function(input, output,session) {
  
  output$Text <- renderText({ c("TestText") })
  
})
shinyApp(ui = ui, server = server)

enter image description here

Community
  • 1
  • 1
Pork Chop
  • 28,528
  • 5
  • 63
  • 77
  • Thanks! Before posting I tried calling `bsTooltip` in `ui.R`, and it didn't work. It worked when I called it in parent `renderUI` element though. Anyway, thanks! – vladli Oct 10 '17 at 13:13
  • How come the tooltip looks much nicer (nice border and shading) in your example than when I run it (plain white box with some of the edges missing, no shadow)? – Simon Woodward May 04 '20 at 21:07
2

In general you can tooltips on any Input and Output object by using their id. For example, I added a tooltip on a downloadButton whose id is downloadData, in the UI.

sidebarPanel(
  downloadButton("downloadData",
    label = "Save and check the Employee List"),
  bsTooltip("downloadData",
     'This is the tooltip where you can add double quotes "like this"'),
      placement = "bottom", trigger = "hover")
)
lokxs
  • 171
  • 10
  • How does your answer differ from the accepted one from Pork Chop? – vladli Aug 06 '18 at 12:35
  • PorkChop has answered your question precisely (hence my +1) related to a text box. My answer is more general since bsTooltip allows you to add a tooltip on any object (not just a text box), like a button, a slide, ..., by using the id of that object. – lokxs Aug 07 '18 at 07:11