R script works locally, doesn't work on shinyapp.io

I am trying to build an R + Shiny application that, at least initially, displays a histogram of date data. It works fine for me on my local system in RStudio, but it does not work in shinyapps.io.

The application is very simple at the moment - the user interface does nothing, and the data is just a small sample of test data.

Works great in RStudio (draws a nice little histogram). When loading on shinyapps.io, the text "title bar" and sidebar are displayed, but after a second or two, either it says that the error "from" cannot be NA, NaN or infinite "or - the screen goes gray and the script stops (? ) in both cases without creating a histogram.

I was puzzled; it would be interesting to hear if anyone has any suggestions on where I made a mistake. Perhaps this is due to as.Date - perhaps a similar problem is reported here without any solutions.

My two brilliant files:

# ui.R shinyUI(fluidPage( titlePanel("title panel"), sidebarLayout( sidebarPanel( ), mainPanel( plotOutput("distPlot") ) ) )) 

and

 # server.R library(shiny) shinyServer(function(input, output){ output$distPlot <- renderPlot({ 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") #plot a histogram hist(num_date, breaks = "years", format = "%Y", freq = TRUE) }) }) 

There are no errors (or nothing but versions, start and listen ...) reported by showLogs ():

2015-02-22T10: 00: 50.507273 + 00: 00 shinyapps [32851]: version R: 3.1.2
2015-02-22T10: 00: 50.509043 + 00: 00 shinyapps [32851]: rmarkdown version: 0.0.0
2015-02-22T10: 00: 50.507340 + 00: 00 shinyapps [32851]: Brilliant version: 0.11.1
2015-02-22T10: 00: 50.509508 + 00: 00 shinyapps [32851]: knitr version: 0.0.0
2015-02-22T10: 00: 50.784283 + 00: 00 shinyapps [32851]:
2015-02-22T10: 00: 50.784285 + 00: 00 shinyapps [32851]: Running Brilliant with the process ID: "14"
2015-02-22T10: 00: 50.792403 + 00: 00 shinyapps [32851]:
2015-02-22T10: 00: 50.792405 + 00: 00 shinyapps [32851]: listening http://0.0.0.0â–ş7429

+7
r shiny
source share
2 answers

You have two problems. First, you missed some quotes in your data. However, the fix did not change the result. I copied your code, fixed the quotation marks, and unrolled it and got the same results (worked locally, but not on shinyapps.io).

The second (and more important issue) relates to how different operating systems handle dates. I changed the .R server data part as follows:

 text_date <- c("2006-03-09", "2008-10-31", "2008-09-24", "2009-02-27", "2014-05-19", "2013-08-07", "2014-12-08", "2010-02-02", "2014-12-22", "2011-12-20", "2009-09-04", "2013-12-19", "2007-10-10", "2008-09-19") 

This worked both locally and on shinyapps.io. Thus, the problem is not with your program, but with how the dates are handled.

I thought the problem could be due to leading zeros required for single-digit dates, but with a change that doesn't fix the problem. However, when I replaced the month names with double-digit numbers, it again worked both locally and on shinyapps.io. Therefore, it seems that shinyapps.io has some difficulty converting month names to date values. However, I do not know why this will happen.

Update : Following the leader provided by Fereshteh Karimeddini , I changed the files by entering the following code: In server.R:

 output$dates = renderText({format(num_date, format = "%d %B %Y")}) output$location = renderText({Sys.getlocale(category = "LC_ALL")}) 

In ui.R:

 textOutput("dates") textOutput("location") 

Interestingly, I got exactly the same results for outputting "dates", regardless of whether I was running locally or on shinyapps.io. I thought I would get the monthly names in French or something else. However, for the output of "location" I had different results. Locally:

LC_COLLATE = English_United States. 1252;
LC_CTYPE = English_United States. 1252;
LC_MONETARY = English_United States. 1252;
LC_NUMERIC = C;
LC_TIME = English_United States. 125

On shinyapps.io:

LC_CTYPE = C.UTF-8;
LC_NUMERIC = C;
LC_TIME = C.UTF-8;
LC_COLLATE = C.UTF-8;
LC_MONETARY = C.UTF-8;
LC_MESSAGES = C.UTF-8;
LC_PAPER = C.UTF-8;
Lc_name = C;
LC_ADDRESS = C;
LC_TELEPHONE = C;
LC_MEASUREMENT = C.UTF-8;
LC_IDENTIFICATION = C

Note: carriages have been added for readability.

There was an error report on the debian forum (I don’t know the relationship with Ubuntu, which uses shinyapps.io) that C.UTF-8 does not contain monthly names. However, this has been since 2012, and the bug report said that it was fixed in a recent release. In addition, if the C.UTF-8 language on shinyapps.io really did not have the names of the months, then it should not have displayed the names of the months (which was done perfectly). It made me wonder if he can give out the names of the months, why can't he read the monthly names? So I tried to get this to do just that. In server.R:

 text_date = c("09 03 2006") num_date <- as.Date(text_date, format = "%d %m %Y") x = format(num_date, format = "%d %B %Y") output$dates = renderText({x}) renum_date = as.Date(x, format = "%d %B %Y") output$redates = renderText({format(renum_date, format = "%d %B %Y")}) 

In ui.R:

 sidebarPanel(textOutput("dates")), mainPanel(textOutput("redates")) 

Locally, sidebarPanel and mainPanel showed exactly the same thing: March 9, 2006. However, on shinyapps.io, mainPanel showed NA. Thus, it would seem that shinyapps.io can wash it, but cannot accept it, at least until the names of the months disappear. How strange is that?

+4
source share

I had the same problem. Shinyapps.io seems to use different language settings. I tried to use% b in the as.Date () function, and it was not able to convert the date correctly, which led to a null record. This completely confused me, because it also did not cause any errors. Debug to find 1 line was not funny!

I created the following inline code to resolve the name of the month because it was formatted in this way in my data source, so I had to convert it:

match ((month), with (“Jan”, “February”, “Mar”, “April”, “May”, “June”, “July”, “August”, “September”, “October” “November” , "December"))

The month in the above code is the name of the variable containing the value of the month name. An example of a complete line using this code:

df $ Date <- with (df, paste (Year, match ((month), c ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", " Aug "," Sep "," Oct "," Nov "," Dec ")) , Day, sep =" - "))

Enjoy it!

+1
source share