Reputation: 586
I want to include a small "Help" actionLink (next to a "Render" actionButton) that acts as a popover (see here). Here's my code:
server.R:
shinyUI(pageWithSidebar(
sidebarPanel(
actionButton("renderButton", "Render"),
actionLink("link", "Help") ),
mainPanel()
))
ui.R:
shinyServer(function(input, output, session) {
# ... dealing with renderButton ...
output$link <- renderUI({
addPopover(session=session, id=output$link, title="",
content="Testing.", placement = "bottom",
trigger = "click", options = NULL)
})
})
Right now, the actionLink shows up on the sidebar, but clicking on it has no effect. Any tips? I think it may have to do with the id in addPopover, but I haven't found many examples to provide a framework. I found this, but I want to deal with the popover in server.R, not ui.R. Can it be done this way, or should I just make the popover in ui.R?
Upvotes: 2
Views: 3057
Reputation: 11908
From ?Tooltips_and_Popovers
:
There must be at least one shinyBS component in the UI of your app in order for the necessary dependencies to be loaded. Because of this, addTooltip and addPopover will not work if they are the only shinyBS components in your app.
To get the pop over to work, you can change your actionButton
into a bsButton
, and modify server.R
to only contain the call to addPopover
. The id
argument to addPopover
also needs to be changed to refer to the id of the ui object you want the pop over to appear on, in your case "link"
, the id of the actionLink
.
Here's the modified example code in a self-contained code chunk:
library(shiny)
library(shinyBS)
runApp(
# Ui
list(ui = pageWithSidebar(
headerPanel("Test App"),
sidebarPanel(
bsButton("renderButton", "Render"),
actionLink("link", "Help") ),
mainPanel("Hello World!")
),
# Server
server = function(input, output, session) {
# ... dealing with renderButton ...
addPopover(session=session, id="link", title="",
content="Testing.", placement = "bottom",
trigger = "click", options = NULL)
})
)
Upvotes: 4