【问题标题】:selectInput resetting without reasonselectInput无故重置
【发布时间】:2020-09-16 18:57:08
【问题描述】:

当我使用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.

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    这里的问题是,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)
    

    【讨论】:

      猜你喜欢
      • 2019-03-05
      • 2015-10-11
      • 2021-01-25
      • 2021-06-13
      • 2017-06-16
      • 2012-04-16
      • 2017-10-20
      • 2019-01-02
      • 2015-09-23
      相关资源
      最近更新 更多