Error: evaluation nested too deeply: infinite recursion / options(expressions=)?

2,175 views
Skip to first unread message

Oliver Wang

unread,
Apr 10, 2013, 7:52:07 PM4/10/13
to shiny-...@googlegroups.com
Hi Guys,
I met a problem called, evaluation nested too deeply: infinite recursion / options(expressions=)?
What I want to do in the shiny is after user enters the start date and end date, the script can help us find the correct time range in the dataframe (not earlier than the start date and not later than the end date) and then plot the energy consumption data with time.

Part of the code is here. This is to generate a plot indicating the energy consumption and time
if (input$consumption) {
  
    output$Plot <- reactivePlot(function() {
      
      start1 = paste0(input$Year1, "-", input$Month1, "-", input$Day1)
      start_energy = as.POSIXlt(start1)
      end1 = paste0(input$Year2, "-", input$Month2, "-", input$Day2)
      end_energy = as.POSIXlt(end1)
    
      shinydayenergy = subset(shinyday, (shinyday$time>=start_energy) &(shinyday$time<=end_energy) )
     
      plot(shinydayenergy$time,shinydayenergy$energy)
    })

I think there is something wrong here,  shinydayenergy = subset(shinyday, (shinyday$time>=start_energy) &(shinyday$time<=end_energy) ).
What do you think?

Thank you so much!
Best wishes,
Oliver

Winston Chang

unread,
Apr 10, 2013, 9:06:24 PM4/10/13
to shiny-...@googlegroups.com
I think instead of this:
   subset(shinyday, (shinyday$time>=start_energy) & (shinyday$time<=end_energy) )
you want to do this:
  subset(shinyday, time>=start_energy & time<=end_energy)



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

Oliver Wang

unread,
Apr 11, 2013, 6:59:05 PM4/11/13
to shiny-...@googlegroups.com
Hi Winston,
I tried to use your method, but the same error occurs.
What's more, shinyday dataframe includes three column. One is time, the second one is energy consumption, the third one is energy cost.
So shinyday$time indicates the time data in the dataframe.

在 2013年4月10日星期三UTC-7下午6时06分24秒,Winston Chang写道:

Winston Chang

unread,
Apr 12, 2013, 4:56:11 PM4/12/13
to shiny-...@googlegroups.com
I was just reminded by Doug's response in another thread: within a reactive expression, using input$x in a subset() likely won't work properly, because subset uses non-standard evaluation, as mentioned in the documentation. It evaluates the filtering expression in the data frame environment, which can cause problems.

Within a reactive expression, this will cause problems:
  subset(data, x == input$x)

But this should work:
  in_x <- input$x
  subset(data, x == in_x)


For writing Shiny apps, it's probably best to use square-bracket indexing instead of subset.

-Winston

王竞凡

unread,
Apr 12, 2013, 6:33:18 PM4/12/13
to shiny-...@googlegroups.com
Hi Winston,
I tried to do some correct. I used  in_x <- input$x and square-bracket indexing together.
Here you can see the codes, https://gist.github.com/OliverBears/5373430. But I still met the problem.

 
Part of the codes show below.
    output$Plot <- reactivePlot(function() {
      
      start1 = paste0(input$Year1, "-", input$Month1, "-", input$Day1)
      start_energy = as.POSIXlt(start1)
      in_start_energy <- start_energy
      end1 = paste0(input$Year2, "-", input$Month2, "-", input$Day2)
      end_energy = as.POSIXlt(end1)
      in_end_energy <- end_energy
      shinydayenergy = shinyday[(shinyday$time>=in_start_energy) & (shinyday$time<=in_end_energy),]
      plot(shinydayenergy$time,shinydayenergy$energy)
    })

Best wishes,
Oliver


2013/4/12 Winston Chang <win...@rstudio.com>

--
You received this message because you are subscribed to a topic in the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/shiny-discuss/AUBTRnSGx3c/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to shiny-discus...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
王竞凡 Jingfan (Oliver) Wang
Advanced Energy Technology, Department of Mechanical Engineering, University of California at Berkeley (Master)
Major: Energy & Environment Systems Engineering, Chu Kochen Honors College,Zhejiang University (Bachelor)
Minor:Intensive Training Program of Innovation and Entrepreneurship, Zhejiang University (Bachelor)
QQ: 493171077

Andrew Clark

unread,
Apr 13, 2013, 10:21:57 AM4/13/13
to shiny-...@googlegroups.com
Oliver
  I just ran your code and got a different error
Error in .getReactiveEnvironment()$currentContext() : 
  Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive function.)

I'm no expert, but is this because your if statements are not within a reactive? You could have one reactivePlot (without the deprecated function()) and put the if statements within that

Not sure this addresses your original problem but never got that far in script

andrew clark

王竞凡

unread,
Apr 13, 2013, 5:05:38 PM4/13/13
to shiny-...@googlegroups.com

Hi Andrew,

I see your point. I made some change. But I met the same problem,evaluation nested too deeply: infinite recursion / options(expressions=)?.

I tried to use other's computer to run the same code, now there isn't the problem as you mentioned.

I still put my code here, https://gist.github.com/OliverBears/5373430

Can anyone help me out?

Best wishes,

Oliver

Winston Chang

unread,
Apr 13, 2013, 7:31:54 PM4/13/13
to shiny-...@googlegroups.com
What version of Shiny are you using? The app runs for me, although it gives a different error:
Error in charToDate(x) : 
  character string is not in a standard unambiguous format


With older versions of Shiny, the reactive({ ... }) construct won't work; you would need to use reactive(function() { ...} ).

-Winston


--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.

王竞凡

unread,
Apr 14, 2013, 12:52:57 AM4/14/13
to shiny-...@googlegroups.com
Thank you for replying to me.
I just downloaded the latest version, 0.5.0. I still met the same problem, evaluation nested too deeply: infinite recursion / options(expressions=)?.
You said that you can run the app. Is it reactive?
Frankly to say, if I can fix it before Wed, it will be great, because the deadline is next Wed. I think I almost finish.
Thank you so much. I am appreciated for your help.

Best wishes,
Oliver

Winston Chang

unread,
Apr 14, 2013, 11:48:38 AM4/14/13
to shiny-...@googlegroups.com
It runs, but no plot shows up. Instead, it displays the error that I mentioned earlier. Did you restart R after installing the new version of Shiny?


Oliver Wang

unread,
Apr 16, 2013, 6:09:56 PM4/16/13
to shiny-...@googlegroups.com
Hi Winston,
I tried to restart. But I still had the problem about recursion.
BTW, I put all the if sentence inside the reactive function.
You said that the character string is not in a standard unambiguous format. 
In this script, the character string is about time. But I don't find any error in time calculation.

Hope to hear from you.
Best wishes,
Oliver

在 2013年4月14日星期日UTC-7上午8时48分38秒,Winston Chang写道:

Joe Cheng

unread,
Apr 18, 2013, 5:58:05 PM4/18/13
to shiny-...@googlegroups.com
I couldn't reproduce the problem about recursion, but got the same error Winston did. That said, there were numerous problems in the code that I could see by inspection, so I did some heavy refactoring and it mostly works now:


The main thing that is still wrong is the date handling (lines 13-16 in server.R). I have no idea what is happening there, or whether there was a reason you were using Date in your data but POSIXlt for the start/end.

However you can see that each plot gets its own renderPlot in server.R and plotOutput in ui.R, and I use conditionalPanel to show or hide them in accordance with the checkboxes.

Hope that helps.

王竞凡

unread,
Apr 25, 2013, 1:57:01 PM4/25/13
to shiny-...@googlegroups.com

Thank you Joe & Winston. Sorry for the late reply.

Now the program is working.

I changed the sentence 

data[data$time >= start && data$time <= end,], to  data[data$time >= start & data$time <= end,].

And I also converted the format of the data in the date frame.

Reply all
Reply to author
Forward
0 new messages