Adding a pop-up window to an output

The addPopover() function from the shinyBS() package allows you to add pop-up windows to input or output elements within a shiny application. This is another one-liner, back in the server.R file, along with the function that draws the graph:

output$trend <- renderPlot({
  ...[functions from previous chapter]...
  if(input$smooth){
    thePlot <- thePlot + geom_smooth()
  }
  print(thePlot)
  addPopover(session, id = "trend", title = "Source",
    content = "All data from Google Analyics website at <a href =
    'http://example.com'>http://example.com</a>",
    trigger = 'click')
})

As you can see, addPopover() takes the session argument, which we gave to shinyServer() at the top, along with the ID of the element that we wish to annotate ...

Get Web Application Development with R Using Shiny - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.