当我使用selectInput的内容来显示某些内容时,它不能正常工作:首先它工作,但它立即重置selectInput。
我使用的是R版本3.5.0和Shiny 1.2.0。
下面是一个极简主义的例子来再现这个行为:
simpleList <- list("..." = -1, "A" = 1, "B" = 2, "C" = 3)
ui <- fluidPage(
mainPanel(
tabsetPanel(type = "tabs",
tabPanel("Test", uiOutput("test"))
)
)
)
server <- function(input, output, session) {
output$test <- renderUI({
tagList(
selectInput("pole", "Pôle", choices = simpleList),
h3(paste0("Pôle : ", poleChoisi()))
)
})
poleChoisi <- reactive({
if("pole" %in% names(input))
return(input$pole)
else
return("...")
})
}
shinyApp(ui = ui, server = server)我想我做错了什么,但我不明白。非常感谢你的帮助。
最好的
ChoCChoK。
发布于 2020-09-16 18:57:09
这里的问题是,selectInput是renderUI调用的一部分。每次更新h3标记时,都会重新呈现selectInput。
请参阅以下内容:
library(shiny)
simpleList <- list("..." = -1, "A" = 1, "B" = 2, "C" = 3)
ui <- fluidPage(
mainPanel(
tabsetPanel(type = "tabs",
tabPanel("Test", selectInput("pole", "Pôle", choices = simpleList), uiOutput("test"))
)
)
)
server <- function(input, output, session) {
output$test <- renderUI({
tagList(
h3(paste0("Pôle : ", poleChoisi()))
)
})
poleChoisi <- reactive({
if("pole" %in% names(input))
return(input$pole)
else
return("...")
})
}
shinyApp(ui = ui, server = server)https://stackoverflow.com/questions/63917767
复制相似问题