r - need to input data into a textbox in shiny -
i making simple system in shiny consist in textbox , number of checkboxes below it. want user enters id textbox , automatically system generates text file name of file same user id. mean if user enters "1234q" id, system generate file named "1234q". far have done following:
#part of ui.r file library(shiny) shinyui(fluidpage( titlepanel(h2("title")), ###textbox entering person data textinput("text2", label = h3("personal id"), value = ""), verbatimtextoutput("textboxvalue"), hr(), mainpanel( textoutput("text1"), #some checkboxes here actionbutton("action", label = "next") ) )) and server.r following:
sw=0 shinyserver(function(input, output, session) { output$textboxvalue <- renderprint({ input$text2 }) observe({ filenamedata<-rendertext({ input$text2 }) filename<<-paste(filenamedata(),sep=".","txt") }) if (sw==0){ #some operations here cat(somedata,file=filename,append=true,sep=",") #save data the problem have after user inputs id got data filename variable, intend use saving data obtain after if(sw==0) part, nothing happens. see program bypasses observe part , goes directly evaluate if(sw==0) part. have tried using isolate , no luck @ all. can solve this?
update:
i have done following:
shinyserver(function(input, output, session) { ###data received textbox, need save file name once ####observe observe({ filenamedata<-rendertext({ input$text2 }) #print(filenamedata()) filename<<-paste(filenamedata(),sep=".","txt") }) isolate({ ###end of data received textbox if (sw==0){ which works fine, missing first data enter because filename empty.
pd. in summary need value of text user inputs textfield , create file same name. process should made once.
if want link execution of if(sw==0{...} 'input$text2, isolate way go. need wrap if .. in isolate, , have inside observer trigger it. should work
observe({ filenamedata<-rendertext({ input$text2 }) filename<<-paste(filenamedata(),sep=".","txt") isolate ({ if (sw==0){ #some operations here cat(somedata,file=filename,append=true,sep=",") #save data } }) }) now isolate() inside of observer , should trigger when input$text2 changes.
Comments
Post a Comment