List all inputs in server.R and create vector of many shiny inputs

3,138 views
Skip to first unread message

Aaron Horowitz

unread,
Nov 7, 2013, 8:07:29 PM11/7/13
to shiny-...@googlegroups.com

Hey guys,

Is there a way to list all of the input$ variables in your interface? I've created many sliders dynamically thanks to renderUI, xtable, and a few custom functions.  I can access the data for each slider individually, but I'd like to be able to access all of them at once and put them in a vector/data frame? How might I be able to do this?

For the first question, I've tried printing str(input), and length of input appears to be 1, so haven't been able to answer that basic question.  

For the second, get("input$whatever") doesn't seem to be working, I'm not sure if there is an easy workaround to this if I can't access input in a list or other format?

I'm limited in how much code I can share, but if this description is insufficient, I'll happily create some sample code (and share how I created a table of slideInputs, if anyone is interested in this functionality)

Regards,
Aaron

Garret Polderman

unread,
Nov 13, 2013, 3:21:08 AM11/13/13
to shiny-...@googlegroups.com
Hi Aaron,

I had to build the same functionality. And this is how i did it

output$colors <- renderUI({
  for(i in 1:nrow(dynamicInputs)){
    textInput(dynamicInputs[i,'id'], dynamicInputs[i,'name'],dynamicInputs[i,'value'])
  }
})

In other function where I wnat to get the values from the inputs
 for(i in 1:nrow(dynamicInputs)){
   doSomethingWithTheInputs <- input[[id]]
  }


Op vrijdag 8 november 2013 02:07:29 UTC+1 schreef Aaron Horowitz:

Stéphane Laurent

unread,
Nov 13, 2013, 5:32:51 AM11/13/13
to shiny-...@googlegroups.com
str(reactiveValuesToList(input)) should be better than str(input)

Aaron Horowitz

unread,
Nov 21, 2013, 10:24:49 AM11/21/13
to shiny-...@googlegroups.com
Thanks for the responses guys! Both helpful

To continue knowledge sharing on this, I ended up using an alternative solution, which doesn't depend on reactiveValuesToList -- which while useful I now realize creates an object that has dependencies across your whole app. Anyway, this is how I got around the "get" problem

#inputVector is a stored vector of slider bars in my case that is created as part of dynamic function that builds them
#my output was originally of the format "input$itemInput" for each item
sapply(inputVectorfunction(x){eval(parse(text=x))})


Thanks all,
Reply all
Reply to author
Forward
0 new messages