首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >selectInput无故重置

selectInput无故重置
EN

Stack Overflow用户
提问于 2020-09-16 18:09:02
回答 1查看 30关注 0票数 0

当我使用selectInput的内容来显示某些内容时,它不能正常工作:首先它工作,但它立即重置selectInput

我使用的是R版本3.5.0和Shiny 1.2.0。

下面是一个极简主义的例子来再现这个行为:

代码语言:javascript
复制
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。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-09-16 18:57:09

这里的问题是,selectInputrenderUI调用的一部分。每次更新h3标记时,都会重新呈现selectInput

请参阅以下内容:

代码语言:javascript
复制
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)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63917767

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档