简体   繁体   English

shiny addpopover function 不适用于 uioutput

[英]shiny addpopover function doesnt work with uioutput

I have created the following shiny App in R我在 R 中创建了以下 shiny 应用程序

First we import the necessary libraries首先我们导入必要的库

 library(shiny)
 library(shinyBS)

The next step is to create a UI as follows下一步是创建一个 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") ) ))

We now create the Server as follows我们现在如下创建服务器

 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)

The App on running will create a slider and two select boxes and an output that reacts dynamically to user input.正在运行的应用程序将创建一个 slider 和两个 select 框和一个动态响应用户输入的 output。 the tooltip displays the bubble with read when one hovers over the slider.当将鼠标悬停在 slider 上时,工具提示会显示带有读取的气泡。 I am unable to get the addpopover function to work.我无法让 addpopover function 工作。 It should work such that based on the input of select 2, the text rendered in the popover message box should change.它应该可以根据 select 2 的输入工作,弹出消息框中呈现的文本应该发生变化。 The App is crashing.应用程序崩溃。 When i place the addpopover command within a reactive environment, I am the renderUI functions output- namely the textbox disappears.当我将 addpopover 命令放在反应式环境中时,我就是 renderUI 函数的输出——即文本框消失了。 I request someone to help me here.我请求有人在这里帮助我。

You can wrap addPopover in observe or observeEvent .您可以将addPopover包装在observeobserveEvent中。 I would prefer observeEvent , as recommended here .我更喜欢observeEvent ,正如这里推荐的那样。

addPopover will be updated each time content() changes, which is what we want since this popover is supposed to show content() . addPopover将在每次content()更改时更新,这是我们想要的,因为这个 popover 应该显示content() However, there is something strange about the behaviour of this popover (clicks are sometimes ineffective) but I guess this is not related to your app in particular.但是,此弹出框的行为有些奇怪(点击有时无效),但我想这与您的应用程序无关。

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM