闪亮:将addPopover添加到actionLink [英] Shiny: adding addPopover to actionLink
问题描述
我想包含一个小的帮助" actionLink(在渲染" actionButton旁边),用作弹出窗口(请参见
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)
})
})
现在,actionLink出现在侧栏上,但是单击它没有任何作用.有小费吗?我认为这可能与addPopover中的id有关,但是我没有发现很多提供框架的示例.我发现了此,但我想处理server.R(而不是ui.R)中的弹出窗口.可以这样做吗,还是我应该在ui.R中制作弹出框?
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?
推荐答案
来自?Tooltips_and_Popovers
:
您的应用的用户界面中至少必须有一个ShinyBS组件 命令以加载必要的依赖项.因为这, 如果addTooltip和addPopover是唯一的shinyBS,则它们将无法工作 应用中的组件.
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
的调用. addPopover
的id
参数也需要更改,以引用要在其上弹出的ui对象的ID,在您的情况下为"link"
,是actionLink
的ID.
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)
})
)
这篇关于闪亮:将addPopover添加到actionLink的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!