Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
checkboxGroupInput在observeEvent之前更新_R_Shiny_Reactive - Fatal编程技术网

checkboxGroupInput在observeEvent之前更新

checkboxGroupInput在observeEvent之前更新,r,shiny,reactive,R,Shiny,Reactive,我试图在点击“提交”按钮后,在复选框GroupInput中选择的值显示在多个选项卡的主面板中。使用observeEvent,第一次选择选项时,在单击submit按钮之前,这些选项不会显示在主面板中,但在单击submit按钮之后,选择后的值会显示在主面板中,而不会提交它们。如何使其在主面板更新之前必须单击“提交” library(shiny) ui <- fluidPage( titlePanel( "Example"), sidebarLayout( sidebarPanel(

我试图在点击“提交”按钮后,在复选框GroupInput中选择的值显示在多个选项卡的主面板中。使用observeEvent,第一次选择选项时,在单击submit按钮之前,这些选项不会显示在主面板中,但在单击submit按钮之后,选择后的值会显示在主面板中,而不会提交它们。如何使其在主面板更新之前必须单击“提交”

library(shiny)

ui <- fluidPage(

titlePanel(
  "Example"),
sidebarLayout(
  sidebarPanel(
    checkboxGroupInput("choice", label = "Choose Letter", 
                       choices = list("A", "B", "C", "D")),
    actionButton("submit", "Submit"),
    width=3
  ),

  mainPanel(
    tabsetPanel(
      navbarMenu("Pages", 
                 tabPanel("Page 1", h3(htmlOutput("choice1"))),
                 tabPanel("Page 2", h3(textOutput("choice2")))
    )
   )
  )
 )
)


server <- function(input, output) {
  observeEvent(input$submit,{
    lapply(1:2, function(nr){
    output[[paste0("choice",nr)]]<-renderText({choose<-paste(input$choice, collapse=", ")
    paste(choose)})
   })
  })
}


shinyApp(ui = ui, server = server)
库(闪亮)

ui我将发布解决方案,但只做少量解释,希望有人能过来解释更多或纠正我的问题

第一:
renderText
直接与“或依赖于”
input$choice
交互,因此
input$choice
中的任何更新或更改都将反映在renderText上。要解决此依赖性问题,您需要一个占位符,该占位符依赖于或使用
observeEvent
触发,即
reactiveValues

server <- function(input, output) {
           data <- reactiveValues()
           observeEvent(input$submit,{
                        data$nr <- input$choice
                        lapply(1:2, function(nr){
           utput[[paste0("choice",nr)]]<-renderText({choose<-paste(data$nr, collapse=", ")
           paste(choose)})
      })
   })
}
有关shiny中反应性和依赖性的更多信息,您可以查看

server <- function(input, output) {
           data <- reactiveValues()
           observeEvent(input$submit,{
                        data$nr <- input$choice
                        lapply(1:2, function(nr){
           utput[[paste0("choice",nr)]]<-renderText({choose<-paste(data$nr, collapse=", ")
           paste(choose)})
      })
   })
}
a<-eventReactive(input$submit,{
paste(input$choice, collapse=", ")
})

 lapply(1:2, function(nr){
        output[[paste0("choice",nr)]]<-renderText(paste(a()))
})