【问题标题】:shiny addpopover function doesnt work with uioutput闪亮的 addpopover 函数不适用于 uioutput
【发布时间】:2020-08-22 23:39:27
【问题描述】:

我在 R 中创建了以下闪亮的应用程序

首先我们导入必要的库

 library(shiny)
 library(shinyBS)

下一步是创建一个 UI,如下所示

ui =  fluidPage( sidebarLayout( sidebarPanel(sliderInput("bins", "Number of bins:", min = 1, max = 
 50,value = 30), selectInput(inputId = "Select1", label = "Select1", choices = c('A', 'B', 'C'), 
 selected = "A"),  selectInput(inputId = "Select2", label = "Select2", choices = c('A1', 'B1', 'C1'), 
 selected = "A1"), bsTooltip("bins", "Read", "right", options = list(container = "body")) ),
 mainPanel(uiOutput("namelist") ) ))

我们现在如下创建服务器

 server =function(input, output, session) {

   content<-reactive({
    input$Select2    
   })
    output$namelist<-renderUI({

    textInput(inputId = "text1", label =input$Select1)

   }) 

 addPopover(session, "namelist", "Data", content =content() , trigger = 'click')  }

 shinyApp(ui, server)

正在运行的应用程序将创建一个滑块和两个选择框,以及一个对用户输入做出动态反应的输出。当将鼠标悬停在滑块上时,工具提示会显示带有读取的气泡。我无法使 addpopover 功能正常工作。它应该根据 select 2 的输入工作,弹出消息框中呈现的文本应该改变。应用程序崩溃。当我将 addpopover 命令放置在反应式环境中时,我就是 renderUI 函数的输出——即文本框消失了。我请求有人在这里帮助我。

【问题讨论】:

    标签: r shiny tooltip popover


    【解决方案1】:

    您可以将addPopover 包裹在observeobserveEvent 中。我更喜欢observeEvent,推荐here

    addPopover 将在每次 content() 更改时更新,这是我们想要的,因为此弹出框应该显示 content()。但是,此弹出框的行为有些奇怪(点击有时无效),但我想这与您的应用无关。

    library(shiny)
    library(shinyBS)
    
    ui =  fluidPage(sidebarLayout(
      sidebarPanel(
        sliderInput(
          "bins",
          "Number of bins:",
          min = 1,
          max =
            50,
          value = 30
        ),
        selectInput(
          inputId = "Select1",
          label = "Select1",
          choices = c('A', 'B', 'C'),
          selected = "A"
        ),
        selectInput(
          inputId = "Select2",
          label = "Select2",
          choices = c('A1', 'B1', 'C1'),
          selected = "A1"
        ),
        bsTooltip("bins", "Read", "right", options = list(container = "body"))
      ),
      mainPanel(uiOutput("namelist"))
    ))
    
    server =function(input, output, session) {
    
      content<-reactive({
        input$Select2    
      })
      output$namelist<-renderUI({
    
        textInput(inputId = "text1", label = input$Select1)
    
      }) 
    
      observeEvent(content(), {
        addPopover(session, "namelist", "Data", content = content() , trigger = 'click')
      })
    
    }
    
    shinyApp(ui, server)
    

    【讨论】:

    • 谢谢。所以有必要将 add popover 包装在一个 observeevent 类型的响应式环境中,以检测 content() 对象的变化。
    • 这里回答了没有响应的问题。 stackoverflow.com/questions/43491305/…
    猜你喜欢
    • 1970-01-01
    • 2015-08-03
    • 2013-03-06
    • 2016-12-14
    • 2020-10-17
    • 1970-01-01
    • 2017-01-09
    • 1970-01-01
    • 2015-11-13
    相关资源
    最近更新 更多