[英]shiny addpopover function doesnt work with uioutput
我在 R 中創建了以下 shiny 應用程序
首先我們導入必要的庫
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)
正在運行的應用程序將創建一個 slider 和兩個 select 框和一個動態響應用戶輸入的 output。 當將鼠標懸停在 slider 上時,工具提示會顯示帶有讀取的氣泡。 我無法讓 addpopover function 工作。 它應該可以根據 select 2 的輸入工作,彈出消息框中呈現的文本應該發生變化。 應用程序崩潰。 當我將 addpopover 命令放在反應式環境中時,我就是 renderUI 函數的輸出——即文本框消失了。 我請求有人在這里幫助我。
您可以將addPopover
包裝在observe
或observeEvent
中。 我更喜歡observeEvent
,正如這里推薦的那樣。
addPopover
將在每次content()
更改時更新,這是我們想要的,因為這個 popover 應該顯示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)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.