user interface - Using input to create UI in Shiny R -


i building app in shiny (r). @ beginning user can upload file use (i doing sort data analysis). goal able use files without knowing how many columns file has, , how data looks like.

so have select columns number, , made small preview app select columns , display them next original:

library(shiny)  ui <-fluidpage(   headerpanel("select data"),   sidebarlayout( sidebarpanel(   fileinput("uploadfile", "xlsx file"),    textinput('vec1', 'choose training columns', "3,4"),   actionbutton("choose","choose data") ), mainpanel(   fluidrow(     column(6,tableoutput("data_raw")),     column(6,tableoutput("data_selected"))   )   )  )  )   server <- function(input, output) {      output$data_raw <- rendertable({      infile <- input$uploadfile     if (is.null(infile))      return(null)       data_raw <<-read.xlsx(infile$datapath, 1)   })    observe({     if(input$choose>0){      selectvec <- as.numeric(unlist(strsplit(input$vec1,",")))       output$data_selected <- rendertable(       data_selected<- data_raw[,selectvec]      )     }    })   }   shinyapp(ui,server) 

now able select columns use on basis of header.

it feels unnatural: changing app while running.. in reactive environment.. why not?

question: how can change ui while allready running, values originating input?

kind regards, pieter

to make me feel not dirty answering this...i didn't debug or handle reactives properly. here ya go. need respond file uploaded on server side, extract column names, , append thosed choices in select input passes down table function column filter.

 upload_app <- function(){   library(shiny)    ui <- bootstrappage(     tags$div(class = "container",              column(3,                     fluidrow(                       fileinput(inputid = 'user_data',                                 label = 'upload data (csv)',                                 multiple = false,                                 accept =  c(                                   'text/csv',                                   'text/comma-separated-values',                                   'text/tab-separated-values',                                   'text/plain',                                   '.csv',                                   '.tsv'                                 ))                     ),                     fluidrow(                       uioutput('column_vars')                     )              ),              column(9,                     tableoutput('filtered_table'))     )   )    server <- function(session, input, output){      var_table <- reactive({       var_data <- input$user_data       read.csv(var_data$datapath, header = true,sep = ",", quote = '')     })      output$column_vars <- renderui({       if(!is.null(var_table())){       selectinput(inputid = 'cols',                   choices = colnames(var_table()),                   multiple = t,                   label = "choose columns")       }     })      output$filtered_table <- rendertable({        if(!is.null(var_table())){         if(length(input$cols)>0){           get_these <- input$cols           new_table <- var_table()[,c(get_these)]         }else {           new_table <- var_table()         }        }else {         new_table <- data.frame(data = 'waiting')       }        return(new_table)      })   }    shinyapp(ui, server)  } 

enter image description here


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -