在模块中使用addPopover

问题描述 投票:0回答:1

我正在尝试使用addPopover中的shinyBS,但无法在模块中使用它。工具提示在模块中可以正常工作,但不会显示弹出窗口。此外,直接放置在主server部分中时,工具提示和弹出框都可以正常工作。在R 3.6.1和RStudio 1.2.1568上用shiny_1.3.2shinyBS_0.61测试。

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)
r shiny shinybs
1个回答
0
投票

您必须使用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?
}
© www.soinside.com 2019 - 2024. All rights reserved.