Common mistakes with Shiny

5,978 views
Skip to first unread message

Stéphane Laurent

unread,
Dec 16, 2013, 3:30:23 PM12/16/13
to shiny-...@googlegroups.com
It could be useful to draw a list of common mistakes with Shiny programming.

1) Extra comma in ui.R
2) input/output id containing a point 

What else ? When someone requiring some help has made such a mistake in his code, we could refer him/her to the list of common mistakes.

Stéphane Laurent

unread,
Dec 16, 2013, 3:33:40 PM12/16/13
to shiny-...@googlegroups.com
3)  ggplot(...) + ... does not work in the output of renderPlot({}); use print(ggplot(...) + ... ).

Stéphane Laurent

unread,
Dec 16, 2013, 3:37:31 PM12/16/13
to shiny-...@googlegroups.com
We should also mention the typical error message generated by these mistakes

1) Extra comma in ui.R : 
"Error in tag("div", list(...)) : argument is missing, with no default"
2) input/output id containing a point
many possible error messages
3)  ggplot(...) + ... does not work in the output of renderPlot({}); use print(ggplot(...) + ... )empty plot in the app


David Ardestani

unread,
Dec 16, 2013, 4:13:25 PM12/16/13
to shiny-...@googlegroups.com
I've seen on the codes here criticisms about using eval(parse(....)) and improper usage of reactive functions (e.g. - put in bad place, should use observe function, etc) .  That could be useful to have in an FYI section.

It would also be helpful to have a section on custom HTML and using the tag commands.  For example, I am trying to create a select input for different colors, and I want to the text to change color depending on the value.  I gather that I should use tags$option.  However, when I try to create my own selectInputColor function based on the code for selectInput, I get an error that it "could not find function choiceWithNames" even though it is used by selectInput.  Perhaps that should be a separate thread topic, but it that sort of general idea where a simple example or two would suffice.

David Ardestani

unread,
Dec 16, 2013, 4:16:50 PM12/16/13
to shiny-...@googlegroups.com
The concept of scoping with respect to working with data files would also be very helpful.


On Monday, December 16, 2013 12:30:23 PM UTC-8, Stéphane Laurent wrote:

Floris Padt

unread,
Dec 16, 2013, 4:25:04 PM12/16/13
to shiny-...@googlegroups.com
what about as.numeric(input$n) instead of just using input$n.

And the global.r file is really helpfull

Patrick Toche

unread,
Dec 17, 2013, 3:57:51 AM12/17/13
to shiny-...@googlegroups.com
What else ? When someone requiring some help has made such a mistake in his code, we could refer him/her to the list of common mistakes.

To quote from you, a common error:

"you cannot assign a value to an input object as if it was an ordinary R object (http://stla.github.io/ShinyPresentationIntroductory/#5) "

Patrick Toche

unread,
Jan 9, 2014, 12:31:52 PM1/9/14
to shiny-...@googlegroups.com
more mistakes seen and personally experienced recently:

1. trying to pass R code to conditionalPanel "condition" instead of javascript, e.g.

condition = "input$cond"  should be condition = "input.cond == true"

(and not TRUE)

another related mistake is something like 

condition = "input.cond1" || "input.cond2"  where the condition is incorrectly broken by closing " too early.

2. trying to pass reactiveValues, as in:

values <- reactiveValues(i=0)

condition = "values.i == 0"


Patrick Toche

unread,
Jan 9, 2014, 12:37:05 PM1/9/14
to shiny-...@googlegroups.com
another one is forgetting to install.packages("somepackage") on the remote server. And slightly more subtle is to have different versions of the packages locally and on the server.

Joe Cheng

unread,
Jan 10, 2014, 5:21:53 AM1/10/14
to Patrick Toche, shiny-...@googlegroups.com
Trying to access a reactive expression without using ().

foo <- reactive({...})

output$plot <- renderPlot({
  plot(foo)
})


On Thu, Jan 9, 2014 at 9:37 AM, Patrick Toche <patric...@usj.edu.mo> wrote:
another one is forgetting to install.packages("somepackage") on the remote server. And slightly more subtle is to have different versions of the packages locally and on the server.

--
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.

Patrick Toche

unread,
Jan 10, 2014, 5:42:30 AM1/10/14
to shiny-...@googlegroups.com, Patrick Toche
Trying to access a reactive expression without using ().

foo <- reactive({...})

output$plot <- renderPlot({
  plot(foo)
})

yes, a very common one for beginners, the mistake is calling the reactive values with foo instead of foo(), i.e. one should have:

output$plot <- renderPlot({
  plot(foo())
})


Also note that:

foo <- reactive({
  a <- something
  return (list(a = a))
})

is accessed with foo()$a rather than just foo().


Another mistake is to forget to return inside foo, i.e. to have say:

  foo <- reactive({
      a <- 1
  })


and in this context, Stéphane's remark about unbalanced and unclosed parentheses, here's one example I've seen:

  foo <- reactive({
      something
  )}



A mistake unrelated to the above is to forget to add session as an argument, when it is used, so to have 

  function(input, output)

when

  function(input, output, session)

is needed.

Stéphane Laurent

unread,
Apr 19, 2014, 1:44:32 PM4/19/14
to shiny-...@googlegroups.com

whenever I try to download, a new app window opens up : there's a typo in the name of downloadButton (it not correspond to the name of the downloadHandler)
Reply all
Reply to author
Forward
0 new messages