How to react on components inserted via the eval() function

425 views
Skip to first unread message

Johnny Baillargeaux

unread,
Feb 13, 2014, 4:51:59 PM2/13/14
to shiny-...@googlegroups.com
Hi,

Using uiOutput (ui.r) and renderUI (server.r) I insert components dynamically but for some reason, the components are extracted from a text variable and displayed using eval(parse()). 
How can i react on components inserted this way because they are not known in advance in UI.R

pseudo code:

ui.r
uiOutput("criteriaList")

server.r
output$criteriaList <- renderUI({

x <- 'textInput("ID", "LABEL", "")'   

eval(parse(text=x))

})

Of course, i have reduced the real source code to pay attention to my real problem because the real source is more complexe and the variable is not so simple.

Cdts,

Vincent

unread,
Feb 13, 2014, 10:16:23 PM2/13/14
to shiny-...@googlegroups.com
Try to avoid eval/parse where possible in Shiny apps. If ID and LABEL are not know you could take a look at Winston's code. 

https://github.com/wch/testapp/blob/master/dynamic_in_out/server.r

If you give some more information we might be able to help you find a more convenient way to achieve the effect you are looking for.

Winston Chang

unread,
Feb 14, 2014, 10:47:24 AM2/14/14
to Johnny Baillargeaux, shiny-discuss
I would very, very strongly recommend NOT using eval() on any code that the user types. A user could easily run any command just by typing in some text with a call to system().

Here's a way to access an input with a name. If the text input is ID, then you can use this:
  input[[input$ID]]

-Winston


--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Stéphane Laurent

unread,
Feb 14, 2014, 11:43:16 AM2/14/14
to shiny-...@googlegroups.com, Johnny Baillargeaux
x <- 'textInput("ID", "LABEL", "")'   
eval(parse(text=x))

generates the same output as 

x <- '<label for="ID">LABEL</label><input id="ID" type="text" value=""/>'
HTML(x)

and the second option is safe.
Reply all
Reply to author
Forward
0 new messages