ThinkR-open / golem

A Framework for Building Robust Shiny Apps
https://thinkr-open.github.io/golem/
Other
915 stars 133 forks source link

Deploying app on shinyapps.io throws errors #670

Closed Camil88 closed 3 years ago

Camil88 commented 3 years ago

Hello, I try to upload my golem app on shinyapps.io but everytime errors are thrown. It's worth adding that locally everything works smoothly. I need to host my app there in no time, unfortunately I can't. Not sure where the problem lies, if it's on the golem side or somehwre else. Deploy got aborted with the error:

Warning message: Error detecting locale: Error in read.table(file = file, header = header, sep = sep, quote = quote, : incomplete final line found by readTableHeader on 'raw' (Using default: en_US)

In my app I have 2 places where I read csv / geojson, it looks like this:

github_csv <- read.csv("https://raw.githubusercontent.com/Camil88/geoMapX/main/data/dataApp.csv", header = TRUE, stringsAsFactors = FALSE, sep = ";")
data_geojson <- sf::st_read(dsn = "https://raw.githubusercontent.com/ppatrzyk/polska-geojson/master/wojewodztwa/wojewodztwa-medium.geojson")

I also followed this advice: https://stackoverflow.com/questions/62041779/unable-to-deploy-shiny-app-with-shinyapps-io. In general, it's all about adding empty line at the end of csv. I tried but my dataset contains coordinates and they can not be empty. I don't know why it's a problem.

I also encountered this:

Warning in loadSupport(appDir, renv = sharedEnv, globalrenv = NULL) : Starting R with process ID: '49' Loading R/ subdirectory for Shiny application, but this directory appears to contain an R package. Sourcing files in R/ may cause unexpected behavior.

Not sure what it means, especially 'but this directory appears to contain an R package'. My whole golem project is stored locally under given path and this is where I want to deploy my app from. If you have any advices, please let me know. It's first time I deploy app on shinyapps.

statnmap commented 3 years ago

Le'ts note that this same question is also posted on Stackoverflow: https://stackoverflow.com/questions/67505281/error-detecting-locale-error-in-read-tablefile-file-header-header-how-t

Cross posted here too: https://community.rstudio.com/t/errors-when-deploying-app-on-shinyapps-io/104550

Camil88 commented 3 years ago

Exactly, but I wrote the app in golem and not sure if it's overall problem or specifically something with deploying the app with this framework. That's why I also decided to ask here because you are experts and all issues on this project github revolve around golem. Moreover I need to deploy the app as soon as possible and look for help. It's my first time with deploying shinyapp.

Camil88 commented 3 years ago

I made a small experiment - wrote very simple golem app, almost nothing there on ui and server side. Just to check if it's possible to deploy golem app on shinyapps. I also wrote another very simple 'single' (not golem) app.R to check if this one can be deployed too. So, in the end I was able to deploy single app.R on shinyapps but it was not possible with golem app. I got an error (see it in logs):

Warning in loadSupport(appDir, renv = sharedEnv, globalrenv = NULL) : Loading R/ subdirectory for Shiny application, but this directory appears to contain an R package. Sourcing files in R/ may cause unexpected behavior.

and also this:

Fatal error: cannot create 'R_TempDir'

Why it cannot create this file? And as for directory where my app is stored - in simple words I created directory on Desktop and this is the place where golem app was created. All files are stored there. Don't know if this might be a reason but every time I close my project in RStudio the following info box comes up:

obraz

And I always save it. In one of my tries to deploy an app I uncheck this '.RData' file (which is workspace I save every time). It doesn't help either. I also set working directory to 'R' (using setdw) folder but deploying failed too. Generally speaking I can't deploy golem app what on the other side is possible when deploying single app.R. Can you deploy your golem apps without no such problems? Maybe I'm doing something wrong? Your help would be appreciated since I have no idea what's going on with it.

statnmap commented 3 years ago

Can you share your simple application as a GitHub repository so that we can help you by trying to reproduce the problem ?
Can you tell us what version of {golem} you used ? If you used the one on CRAN, does the version here on GitHub has the same problem ?

install.packages("remotes")
remotes::install_github("ThinkR-open/golem")

Restart your RStudio session and run again

golem::add_shinyappsio_file()
Camil88 commented 3 years ago

I reinstalled golem from GitHub, as you advised. Nothing changed though. Here is my simple example - https://github.com/Camil88/golemApp. I added links to some GitHub resources in main module as well. Don't know why but if I run the app in console then it throws an error that '%>%' can't be found. Anyway, even if I don't use pipe then it throws error. Error as above - sometimes it's issue with read.table, sometimes with R subdirectory or 'cannot create 'R_TempDir'. I uploaded on GitHUb all files related to this test app.

statnmap commented 3 years ago

I corrected your code to allow doc and dependencies. A golem is a R package, you need to use the same tools as if you were building a R package. This means listing deps in the DESCRIPTION and create functions documentation.
You can do both at the same time using attachment::att_amend_desc() each time you modify something in your code.
You can look at the PR I opened on your repo: https://github.com/Camil88/golemApp/pull/1 The application is deployed correctly on ShinyApps.io there: https://statnmap.shinyapps.io/golemApp/

Camil88 commented 3 years ago

So that was the reason! Yes, it works now, I deployed my app on shinyapps correctly. I'm extremely grateful for your kind help. You saved my life! Again, big thank you!!! :)

statnmap commented 3 years ago

Glad it helps. Remember that a golem is a package. You should run devtools::check() before trying to put in production to solve main issues.