Add to a list in Shiny

前端 未结 1 1431
醉话见心
醉话见心 2021-02-09 13:23

I want to define a list that a user may update through doing certain actions. I did this:

runApp(list(
  ui=fluidPage(
    h1(\'Example\')
    ,textInput(\'txt\'         


        
1条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-09 13:49

    You can use reactiveValues

    require(shiny)
    runApp(list(
      ui=fluidPage(
        h1('Example')
        ,textInput('txt','','Text')
        ,actionButton('add','add')
        ,verbatimTextOutput('list')
      )
    
      ,server=function(input,output,session) {
        myValues <- reactiveValues()
        observe({
          if(input$add > 0){
            myValues$dList <- c(isolate(myValues$dList), isolate(input$txt))
          }
        })
        output$list<-renderPrint({
          myValues$dList
        })
      }
    
    ))
    

    shiny app

    0 讨论(0)
提交回复
热议问题