r - 在模块中使用 addPopover
问题描述
我正在尝试使用addPopover
from shinyBS
,但无法让它在模块中工作。工具提示在模块中工作正常,但弹出框不显示。此外,直接放置在主要server
部分时,工具提示和弹出框都可以正常工作。shiny_1.3.2
在 R 3.6.1和shinyBS_0.61
RStudio 1.2.1568 上进行了测试。
library(shiny)
library(shinyBS)
counterButton <- function(id, label = "Counter") {
ns <- NS(id)
tagList(
actionButton(ns("button"), label = label),
bsTooltip(id = ns("button"), title = "Info about the button"),
verbatimTextOutput(ns("out"))
)
}
counter <- function(input, output, session) {
count <- reactiveVal(0)
observeEvent(input$button, {
count(count() + 1)
})
output$out <- renderText({
count()
})
addPopover(session,
id = "out",
title = "Info",
content = "More info about the counter field",
trigger = "hover")
count
}
ui <- fluidPage(
counterButton("counter1", "Counter #1")
)
server <- function(input, output, session) {
callModule(counter, "counter1")
}
shinyApp(ui, server)
解决方案
你必须使用session$ns
:
counter <- function(input, output, session) {
ns <- session$ns
count <- reactiveVal(0)
observeEvent(input$button, {
count(count() + 1)
})
output$out <- renderText({
count()
})
addPopover(session,
id = ns("out"),
title = "Info",
content = "More info about the counter field",
trigger = "hover")
#count # what's that?
}
推荐阅读
- python - 如何在 Tkcalendar 中翻译日期和月份的名称?
- java - 将布尔值从 false 更改为 true
- swift - SwiftUI 与 maxWidth 的文本对齐不起作用
- reactjs - 如何在 React 中将 ImgBB api 与 Axios 一起使用?
- tensorflow - 无法从 keras 导入顺序模型
- vue.js - 如何隐藏浏览器控制台中的错误?
- r - 尝试在删除了两个变量的情况下运行密度图后鼠标时发生密度图错误
- java - 如何区分移动 POS 设备和安卓手机
- flutter - 如何在 Flutter 中为每个交错的 GridView 框设置不同的颜色
- c++ - 我的预制件不包含二进制文件或包含