【问题标题】:Shiny: adding addPopover to actionLink闪亮:将 addPopover 添加到 actionLink
【发布时间】:2015-07-13 16:11:45
【问题描述】:

我想包含一个小的“Help”actionLink(在“Render”actionButton 旁边)用作弹出框(请参阅here)。这是我的代码:

服务器.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中制作弹出框?

【问题讨论】:

  • 使用shinyBS包怎么样?
  • 就是这样,就是不知道怎么实现。

标签: r twitter-bootstrap shiny popover


【解决方案1】:

来自?Tooltips_and_Popovers

在您的应用程序的 UI 中必须至少有一个 shinyBS 组件 为了加载必要的依赖项。因为这, 如果 addTooltip 和 addPopover 是唯一的 shinyBS,则它们将不起作用 应用中的组件。

要使弹出窗口正常工作,您可以将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)

  })
)

【讨论】:

猜你喜欢
  • 2020-08-22
  • 1970-01-01
  • 2018-03-09
  • 2021-07-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-15
相关资源
最近更新 更多