Getting an error when trying to publish my shiny app to the server for others to view - r

My shiny app runs fine in my local environment, however, when I go to publish it online I get the error "An error has occurred. The application failed to start. Contact the author for more information."
When I review the error I get:
"Line 36 Paths should be to files within the project directory"
"Line 38 Paths should be to files within the project directory"
Here is the code for both of those lines:
36.
data <- read_excel("~/data/T Version/Values for R/Pricing 081021.xlsx") %>%filter(Date_of_Indication == max(Date_of_Indication))
38.
portfolio <- read_excel("~/data/T Version/Values for R/Portfolio for R 081021.xlsx")
I'm a bit stumped as to why it isn't working, any help would be much appreciated.
Thanks

The online app doesn't have access to your local directory. You need to either include the data in the code itself with something like dput() or include the URL to the raw data file via GitHub or something similar.
For example, I use code like this to read a csv from my GitHub repository for my online apps:
dat<-read.csv("https://raw.githubusercontent.com/UserName/RepoName/DataInput.csv")
But note that the repo has to be set to be publicly available (not private).
A potentially helpful link: https://shiny.rstudio.com/tutorial/written-tutorial/lesson7/

Related

R Studio crashing not at initialization. Error: Error occurred during transmission

Some context on my environment:
I am running R Studio in a docker container called rocker/verse.
I downloaded this dataset from Kaggle, which has about 470 MB.
When working with it, at some point RStudio restart. It does't happen after a specific call, and I've seen the same problem when working with other projects. Though it is not related to my code, I am posting it bellow.
library(data.table)
fraud<- fread("path.csv")
fraud1<- sort(sample(nrow(fraud), nrow(fraud)*.7))
train<- fraud[fraud1, ]
test<-fraud[-fraud1, ]
Usually on the console this message is printed:
Error: Error occurred during transmission
And, this pop up is also showed:
I have no idea what is causing it. I would appreciate any help.
Delete the .Rhistory files associated with the installation and any open project.
You have a problem with your user data files for Rstudio. Follow the hints given here: https://community.rstudio.com/t/rstudio-server-error-occurred-during-transmission/84258 and here: https://support.rstudio.com/hc/en-us/articles/218730228-Resetting-a-user-s-state-on-RStudio-Server.

Rshiny publish error: inferAppPrimaryDoc Execution halted

I created an Rshiny APP on my Mac and tried to upload to shinyapps.io
However, when I press 'Publish' button at the top right corner, it shows an error.
Preparing to deploy application...DONE
Uploading bundle for application: 609021...Error in inferAppPrimaryDoc(appPrimaryDoc = appPrimaryDoc, appFiles = appFiles, :
Application mode static requires at least one document.
Calls: <Anonymous> ... withStatus -> force -> bundleApp -> inferAppPrimaryDoc
Execution halted
This problem has been solved. See the first answer.
But now, I have another problem.
I can publish it, but the app cannot show the graphs.
I check the log and it says,
Warning: Error in : Aesthetics must be either length 1 or the same as the data (1): x, y, label, vjust, fill
Also, there is another warning,
Warning in Ops.factor(Year, start) : ‘>=’ not meaningful for factors.
It is pretty strange because when I run the app on my own laptop, it works super well. Please help...
Thanks,
Weichen
You don't have to split your code to ui.R and server.R.
Here is how I solved it on Rstudio:
I created a new Shiny app.R file.
This creates a new folder inside the working directory. I copied all data files I use inside my app into that folder.
I copied and pasted my whole code into the new app.R file on Rstudio.
I clicked Publish and I chose all the data files I use together with the app.R for upload.
It worked. I am not sure why it wasn't working before even though I was still choosing the right files together; I guess because they weren't in the right folder for the Shiny app.
edit: don't forget to Save the app.R file before publishing
Solved.
At first, I simply execute the shiny.R (the whole code) Wrong!
Try this. Create two r files under the same directory.
ui.R
server.R
and then executive shiny.R
You would see an amazing thing happen.
Solved the second problem.
Change the type of 'Year' to numeric by as.numeric
However, I still cannot understand because I can run app on my own laptop.
BTW, the logs in shinyapps.io help me target the problem.

Using R-Portable: what directory is used to access static csv files

I've been looking for a way to share an R app across a few private computers so I was looking at the following link on R-Portable:
https://www.r-bloggers.com/deploying-desktop-apps-with-r/
I was able to follow the instructions and launch the app. The interface pops up and then I see that my visualizations show that no objects are appearing. Part of my app relies on server connections and that data comes through. But other stuff is in static tables for now aka csv files. Below is an example of the shiny log error file:
Warning: Error in subset: object 'car_data' not found
Stack trace (innermost first):
71: subset
70: inherits [C:\Users\john\Desktop\copydist\TestApp\shiny\/server.R#13]
69: as.widget
68: func
67: output$stops_per_day
1: shiny::runApp
I'm not sure where these should be dumped in order for R-Portable to read them in. The program runs perfectly until it hits read.csv in which case it apparently doesn't find the object. Anyone know the proper folder within R Portable to drop the data? Based on the guy's instructions in the link im not sure what the default directory is.
Appreciate the help guys
You can also try using my package, RInno, which I developed after reading the same article.
To get started:
install.packages("RInno")
require(RInno)
RInno::install_inno()
Then you just need to call two functions to create an installation framework in app_dir, which should be the directory with your ui.R and server.R and app_dir/data/.*.csv:
create_app(app_name = "myapp", app_dir = "path/to/myapp")
compile_iss()
This will package everything up into an Inno Setup installation wizard in a directory called "RInno_installer".

Error deployApp when uploading bundle for application - shinyapp

I'm trying for the first time to deploy an App on ShinyApp.io and I manage some issues do it.
I ran the command :
>shinyapps::deployApp('C:/Users/Karim/Documents/test')
And the following message appeared :
Preparing to deploy application...DONE
Uploading bundle for application: 66633...
Error in digest::digest(file.path(appDir, file), algo = "md5", file = TRUE) :
The file does not exist: C:\WINDOWS\TEMP\RtmpugxfSW\fileabc59e7164e/..
I noted that the file mentioned (C:\Windows\Temp...) does exist and contains ui and server files. Yet I don't know which file is missing.
I tried to see if there was no similar cases in the forum by I didn't find similar mistakes.
If anyone know how to solve this error or guide me.
Thank you in advance.
Karim.
Try using relative rather than absolute paths,
https://support.rstudio.com/hc/en-us/articles/229848967-Why-does-my-app-work-locally-but-not-on-shinyapps-io-

Shiny App Error: /v1/applications/ 400 - Validation Error Execution halted

Hi I'm having a million problems trying to publish my app to shiny.io.
Firstly, I have Rtools 3.2 installed in my computer and set to the Path, but it is not recognized in the registry. Nevermind, this code should fix it:
install.packages("installr")
library(installr)
install.Rtools(choose_version = FALSE, check = TRUE, use_GUI = TRUE,
page_with_download_url = "http://cran.r-project.org/bin/windows/Rtools/, keep_install_file=TRUE")
install.packages("devtools")
library(devtools)
devtools::install_github('rstudio/shinyapps')
Next, to deploy my app to my shiny.io account:
library(shinyapps)
shinyapps::setAccountInfo(name='xxxx', token='xxxxxxxxxx', secret='xxxxxxxx')
Then my app starts running in a browser, and I click publish to my shiny account. However, when the app is being deployed, it shows the following error:
Preparing to deploy application...Error: /v1/applications/ 400 - Validation Error
Execution halted
Any ideas what the problems may be? Thank you.
I had the same error returned. In my case the problem was the name of the app itself. Deployed apps must have names at least 4 characters long with no spaces.
Setting an application name solved this problem for me. My application directory contained a space.
deployApp(appName = "myapp")
I had the same problem, however, my app name was fine and even adding 'appName =' did not help. Just a side note that this issue came up because I changed the name of my folder in effort to change the name of my app in shinyapp.io
The only thing that worked for me is publishing through the "Publish" button of Rstudio on upper right. I would recommend publishing using that instead of command. You can select files you do not want to publish within the App folder and you can publish the app under a different name then your local name.
I also had similar errors and the issue was resolved after I changed the name of the directory that holds the "app.R" file from only 3 characters to more than 4 characters.

Resources