闪亮:将 addPopover 添加到 actionLink

Shiny: adding addPopover to actionLink

我想包括一个小的 "Help" actionLink(在 "Render" actionButton 旁边)作为弹出框(参见 here)。这是我的代码:

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)
   })
})

现在,actionLink 显示在侧边栏上,但点击它没有任何效果。有小费吗?我觉得可能和addPopover中的id有关,但是我没找到很多例子来提供框架。我找到了 this,但我想处理 server.R 中的弹出窗口,而不是 ui.R。可以这样做吗,还是我应该只在 ui.R 中制作弹出窗口?

来自?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.

要让弹出窗口正常工作,您可以将 actionButton 更改为 bsButton,并将 server.R 修改为仅包含对 addPopover 的调用。 addPopoverid 参数也需要更改为引用您希望弹出框出现的 ui 对象的 ID,在您的例子中 "link"actionLink .

的 ID

这是独立代码块中修改后的示例代码:

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)

  })
)