Error in shinytest. Cannot detect my script is a R file - r

I am trying to test an shiny application with the function shinytest.
I have made an record and get a new file:
The picture show my test file and how I have specified the path to my application
When I try to run the app I get the following error:
Error in is_rmd(path) :
Unknown whether app is a regular Shiny app or .Rmd: C:/Users/LUCBA/Projects/markt_to_marketpricingtool/test/myshinyapp.R
I know the file is an R file, but I get the error anyway.
Why is this happening and what can I do to fix it?
Best Lucas

This was the code that caused an error in Lucas's original question
app <- ShinyDriver$new("C:/Users/LUCBA/Projects/markt_to_marketpricingtool/test/myshinyapp.R")
The problem is that the first (path) argument to shinytest::ShinyDriver$new can only be a directory (containing either an app.R file or a server.R/ui.R pair) or R markdown .Rmd file. Sadly, a Shiny app file cannot be specified directly by name, so it can't be named myshinyapp.R.

Related

sh permission denied in exams2pdf

I use R/exams to generate a PDF exam like this:
exams2pdf("swisscapital")
However, this results in the following error:
Loading required namespace: tinytex
sh: : Permission denied
Doing the same with exams2html() works well.
What is the problem and how can I fix it?
Given that this does not produce an "error" within R but only on the shell (sh), this is probably just a problem of displaying the PDF interactively at the very end. You can check whether
getOption("pdfviewer")
is correctly set to an application for viewing PDFs (e.g., "/usr/bin/evince") and whether you have permission to use that application.
If there are problems with getting a proper PDF viewer called from within R, then simply use
exams2pdf("swisscapital", dir = ".")
which will write the PDF to your current working directory rather than displaying it in the PDF viewer. And then you can manually open the PDF outside of R.

Shiny prerendered on a network location

I built up a shiny solution that is placed in a R-markdown file.
I use runtime: shiny_prerendered
When I do that obviously the code wants to create an html file within the directory but since it is on a network location I do recieve and error:
Error in shiny_prerendered_prerender(input_rmd, rendered_html, output_dir, :
Unable to write prerendered HTML file to \\192.168.88.150/Main/2.Applications/Program/app.html
Calls: <Anonymous> ... shiny_prerendered_html -> shiny_prerendered_prerender
Execution halted
It seems the issue here is that it tries to write to incorrectly specified directory - starting with "\\", rather than "\\\\", for example.
Couple of notes:
When I move the solution to my local pc - works perfectly fine
Everywhere in the code I'm using relative path of the sort "data.R", rather than "\\\\192.168.88.150\\Main\\2.Applications\\Program\\Data.R" since I'm about to move this to shinyapps.io
If I use runtime:shiny it again works perfectly fine on the server but this is probably due to no need to write down a file.
Any idea how to change the path for the html file or other workaround?
I have rights to write on this network location - that's for sure.

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.

Warning: Error in <Anonymous>: cannot open file 'Rplots.pdf'

After I deploy my R shiny App in web server, it produced such errors. Can anyone help me to solve it? Thanks.
This error is very weird. I can run it in Shiny web server (http://www.shinyapps.io/). But I can not run it on my own web server. I commented out the code which produce pdf. But the error is still existing.
su: ignore --preserve-environment, it's mutually exclusive to --login.
Listening on http://127.0.0.1:37436
Warning: Error in : cannot open file 'Rplots.pdf'
48:
Execution halted
The following code solves my problem:
chown -R shiny:shiny /srv/shiny-server
When generating plots on Shiny server, it automatically tries to create a PDF file.
You can remove this functionality by having the below in your code, before the plotting function.
pdf(file = NULL)
This is probably because your code has a function that generates a plot, and the server is, by default, trying to save it to a pdf file because it's a non-interactive session (that is, it does not display it on the screen).
The fix is to find that statement and remove it.

What is the working directory for a shiny app?

I have set up a Shiny server on Linux at this path
/srv/shiny-server/myApp
This app calls data, which are stored (though a symbolic link) in
/srv/shiny-server/myApp/data/input.txt
and opened with the relative path
"data/input.txt"
When calling this app :
my_ip_adress:3838/myApp
It breaks, not finding the data. I guess it is a path issue, but the idea of a R package is self-containment, so this relative path should be fine.
I have tried with the full path:
"/srv/shiny-server/myApp/data/input.txt"
but get
Warning: Error in fread: File '/srv/shiny-server/myApp/data/input.txt' does not exist. Include one or more spaces to consider the input a system command.
Am I missing something?

Resources