R script working locally; not working on shinyapps.io

211 views
Skip to first unread message

Nik T

unread,
Feb 23, 2015, 7:54:35 PM2/23/15
to shinyap...@googlegroups.com
Hi,

I'm trying to put together a R + Shiny app that, at least initially, plots a histogram of date data. I have it working just fine on my local system in RStudio, but in shinyapps.io it doesn't work.

I've posted this question (and the code) on stackoverflow (https://stackoverflow.com/questions/28656683/r-script-working-locally-not-working-on-shinyapp-io) but noone's suggested an answer yet.   

The app, at the moment, is very simple - the user interface doesn't really do anything, and the data is just a small sample of test data.

Works fine in RStudio (draws a nice little histogram). When loaded on shinyapps.io, the 'title panel' text and sidebar display but after a second or two either it - reports the error "'from' cannot be NA, NaN or infinite" or - the screen greys out and the script stops (?) in both cases without producing a histogram.

Has me baffled; would be interested to hear if anyone has any suggestions for where I've gone wrong.

Cheers,
Nik

Paul de Barros

unread,
Feb 23, 2015, 11:42:23 PM2/23/15
to shinyap...@googlegroups.com
I just posted an answer on stackoverflow.  It looks like shinyapps.io might have some difficulty converting month names to date values.

Nikolas Tumbri

unread,
Feb 24, 2015, 6:45:08 AM2/24/15
to shinyap...@googlegroups.com

Thanks Paul.

Whoops re the quotes - must have happened when I generated the sample data.

Yes, I agree it does look like a shinyapps.io problem (with as.Date). I suppose I could just implement my own as.Date function to get it working - but it would be nice to know what's causing the problem and to get it fixed properly.

Thanks again for your efforts - at least I'm not going crazy! This is the first time I've ever tried R (and shiny, obviously) - I was bracing myself for an obvious oversight (like the missing quotes).

Cheers
Nik

Fereshteh Karimeddini

unread,
Feb 24, 2015, 11:23:15 AM2/24/15
to shinyap...@googlegroups.com
Nik,

Dates could be affected by locale settings on the system, and that's why you see a different behavior on shinyapps.io. To get around that (besides the solution that Paul provided), you could set the locale to "C" in your code, something like this:

    orig_locale <- Sys.getlocale("LC_TIME") 
    Sys.setlocale("LC_TIME", "C")
    text_date <- c("9 March 2006", "31 October 2008", "24 September 2008", "27 February 2009", "19 May 2014", "11 December 2009", "7 August 2013", "8 December 2014", "2 February 2010", "22 December 2014", "20 December 2011", "4 September 2009", "19 December 2013", "10 October 2007", "19 September 2008")
    num_date <- as.Date(text_date, format = "%d %B %Y")
    Sys.setlocale("LC_TIME", orig_locale)


Fereshteh

Nikolas Tumbri

unread,
Feb 24, 2015, 3:06:45 PM2/24/15
to shinyap...@googlegroups.com
Thanks Fereshteh,

That's a good tip, but unfortunately it didn't solve the problem.

However, 12 gsubs later, I've now worked around the behaviour and my app works.

Cheers,
Nik

--
You received this message because you are subscribed to a topic in the Google Groups "ShinyApps Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/shinyapps-users/VHKCz5B0QfE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to shinyapps-use...@googlegroups.com.
To post to this group, send email to shinyap...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shinyapps-users/c8825522-bdf2-45d5-831b-01b172c6ad48%40googlegroups.com.

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

Paul de Barros

unread,
Feb 24, 2015, 3:36:11 PM2/24/15
to shinyap...@googlegroups.com
Fereshteh, I think you are right, at least about the locale issue.  I found the following information here:
If format is specified, remember that some of the format specifications are locale-specific, and you may need to set the LC_TIME category appropriately via Sys.setlocale. This most often affects the use of %b, %B (month names) and %p (AM/PM).

Just to check it out, I altered the program to output the dates and the system locale.  I will be posting it with the stackoverflow question.

Nikolas Tumbri

unread,
Feb 24, 2015, 4:42:23 PM2/24/15
to Paul de Barros, shinyap...@googlegroups.com
Thanks Paul - good bit of detective work and quite an interesting result!

--
You received this message because you are subscribed to a topic in the Google Groups "ShinyApps Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/shinyapps-users/VHKCz5B0QfE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to shinyapps-use...@googlegroups.com.
To post to this group, send email to shinyap...@googlegroups.com.

Fereshteh Karimeddini

unread,
Feb 24, 2015, 5:41:46 PM2/24/15
to shinyap...@googlegroups.com, pj.de...@gmail.com
Yes, Paul, nice detective work.
Reply all
Reply to author
Forward
0 new messages