Script using GPU throws error when running app on Shiny server - r

I have written some code in R using the Shiny package. The app runs alright when running shiny::runApp() from RStudio.
I've tried to host the app on a Shiny server and the GUI starts up correctly. However, a plot should appear on the right when the button "Enviar informacion" is clicked. (You can see how the app looks here, but it won't work though because that link is not on Shiny server but on Shinyapps.io).
The relevant part of the logfile is the following:
Listening on http://127.0.0.1:38327
Loading required package: Rcpp
Warning: Error in [: subscript out of bounds
211: FUN [/srv/shiny-server/spike_sorting/server.R#82]
210: apply
209: cluster_som_h [/srv/shiny-server/spike_sorting/server.R#82]
...
So the error is inside the function cluster_som_h. After trying some stuff, I found out what is causing the error, but don't know how to fix it. Inside this function, I make use of the function Rsomoclu.train() from the package Rsomoclu, with kernelType = 1. This means that the function is run on the GPU. If I set kernelType = 0, then the app works okay with both runApp() and from the Shiny server. So that's where the problem is: for some reason, running the function on the GPU is not working if the app is run from the Shiny server, but it does work if it is run from RStudio using runApp().
Maybe there is something going on because I have CUDA installed on my computer but when I try to run it from the server something happens. Is there a way to fix this? I believe running the code from this specific computer no matter where on the LAN the app is run would solve this. Is this possible?

After doing some (basic) research, I found out what was happening. I have CUDA installed only in my user in Ubuntu, so I had to change the first line of the file /etc/shiny-server/shiny-server.conf so that the user was the right one:
# Instruct Shiny Server to run applications as the user "my_name"
run_as my_name;

Related

How to execute an R shiny script from the command line

I've created a single R file 'myfile.R' which is composed of several functions, reading from an odbc connection, and of course the ui and server components for the shiny application. The goal is for the user to treat this as an executable, that is, I'd like them to be able to run this app without having to run Rstudio. Currently on this environment, Rstudio is installed (as are the relevant packages), what I'm currently writing in command line is:
Rscript myfile.R
The file looks to be successfully loaded, but the application itself does not 'pop up' towards me, infact nothing does, it just says that it is listening on http....
I was thinking of creating a bash script that could do this, and this seemed to be the most simple approach but this is not working.

How to run a shiny app in IntelliJ (PyCharm)

I have a basic shiny app (ui.r and server.r) that I am able to run in RStudio.
But seems like I can't run it in IntelliJ.
I have installed the R language support plug-in and I can run r scripts.
But when I try to run ui.r, the only thing I get is html output in the console.
Does anyone recognise this? I probably forgot to configure something?
I do have experience running java (web) apps with IntelliJ. With tomcat setup e.g.
In the run configurations, I didn't see anything specific for a shiny server or something R related. So I guess that is not where I should search ...
Any idea? Is more information needed?
Thx in adavance.
edit:
The answer is here: https://youtrack.jetbrains.com/issue/R-895
To run a shiny App (R framework) on PyCharm you must enable R first and indicate where is the R interpreter located:
R options appears on the bar status. One of them is R Console. Click on it. Write getwd() command to see if you are in the root directory of the project. If not, set it with setwd() command:
Next, write runApp() and DO NOT press enter yet. You must press alt+enter and then click on load Shiny:

R shiny and rscript.exe

I have tried to make use of a .bat in windows to open and run an r shiny app.
It all works and I even get the listening prompt displayed.
However, no web interface opens.
Has anyone else met this problem and resolved it?

How to debug R-Shiny code with VS Code

Is there any way to debug Shiny (R) inside VS Code? I can easily debug Shiny apps inside RStudio but I like to code inside VS Code so looking for the way to debug R code inside VS Code.
Seems, shiny can be debugged in VSCode using browser-statements 🙌
Prerequisites
Setup this VSCode extensions (VSCode R Guide)
R (by Yuki Ueda)
R Debugger
Use a default app structure (see docs of appDir when running ?shiny::runApp for possible setups)
Set your VSCode workspace to the R projects root (e.g. File -> Open Folder... -> myProject)
Debugging
Set your breakpoints using browser() (RStudio Article)
Run R-Debugger in Launch R-Workspace mode
Execute shiny::runApp() in the Debug Console as soon the Debugger pauses
Your app should fire up in a browser and the breakpoints pause the execution 🎉
Further Ressources
VSCode Article on debugging (can be very helpfull)
Issue on this topic in the VSCode-R-Debugger repo
I was not able to see plots or html (e.g. from plotly) when in debugging mode. I already had "httpgd" as plotting device enabled. The option says it also changes the corresponding R option vsc.use_httpgd, but I checked it was NULL. Setting it explicitly in my .Rprofile or also live in the debugging session allowed me to see plots again, e.g. via print(plot(1:5)).
# For your .Rprofile
options("vsc.use_httpgd" = TRUE)
# code to check if option is set
# getOption("vsc.use_httpgd")
HTH

Fatal error when deploying a shiny app with Rstudio

I have a shiny app (divided into ui.R, server.R and helpers.R) which works on my local machine. The app does not load any libraries besides library(shiny). I am unable to deploy it to shinyapps.io. That is what I do
I log myself into shinyapps.io (via the website www.shinyapps.io)
I run library(rsconnect) on the R console.
I copy the Tokens code (rsconnect::setAccountInfo...) from the www.shinyapps.io page into the R console and run it.
I run the app in Rstudio (1 warning: Warning in body(fun) : argument is not a function). The app runs as expected.
I use the "publish" button in the app window and get a new window saying: "R session aborted. R encountered a fatal error. The session was terminated"
Sorry, I have no idea about where to look for the error. Can you give me a hint what causes the problem? Which additional information would you need to help me?
Thanks a lot!
update: I just saw that there is a second "publish"-button in Rstudio if you have one of the app-files in the editor (without running it). When I use this one, I get the same crash, but with some more information: unexpected exception: boost::filesystem::unique_path: key is not valid in specified status (sorry, that is my own translation from German).
One way of deploying an app to the shinyapps.io server is not to use the button in RStudio, but to do it via the console. Here the steps that are working for me now (RStudio 1.0.143):
Log in on shinyapps.io (via the website www.shinyapps.io)
Run library(rsconnect) on the R console.
Copy the Tokens code (rsconnect::setAccountInfo...) from the www.shinyapps.io page into the R console and run it.
Run rsconnect::deployApp('path to your app') on the R console.
Pushing the publish button in RStudio still results in a crash of R.

Resources