Shiny application started with Rscript and CMD is unavailable after time - r

I have a small .bat script that runs an app using "Rscript" when the user logs in. After some time, the application / server becomes unavailable. There is no error, the page only loads for forever. When the app is started manually through RStudio there is no problem with the access to the app even after days of running. Any idea what causes this and how to solve it?

I think this will help you. It is supposed to be the correct way to launch a R Shiny app.
R -e "shiny::runApp('~/shinyapp')"
(1st result on Google ... Pardon my tone, but have you searched for this before to ask Stackoverflow how to deal with this problem?)

Related

RInno shiny app unable to launch if previous session closed unexpectedly

I have made a Desktop shiny app for windows using the amazing package RInno but I have been experiencing some inconsistencies with launching the application. Occasionally the application will not quit its session properly, leaving R running in the background. Their github suggests using this chunk of code in the server function to insure R is properly terminated when the session ends. I can tell when the application quits properly because I include a custom function that copies the log files to a new indexed name for records and debugging.
if (!interactive()) {
session$onSessionEnded(function() {
write_logs_out() #My custom function. renames logs and stores backups of session data in .rds files
stopApp()
q("no")
})
}
In these cases a new log file is not made so I assume stopApp() and q("no") are never executed as well, leaving R running in the background. One major issue is I do not know how to reproduce this error. My current guess is that this occurs when the R session locally becomes unresponsive. While R is still running in the background, the shiny app never fully opens to a web browser. I will first need to open task manager and quit any R sessions (usually with the name "R front-end") in order to get the app working again.
Since I dont know how to expect this random error, I was wondering if any windows experts could help me write a script that will check if an R process is running, and then kill it. This would at least
I know that
tasklist | findstr Rscript.exe
will list all the current Rscripts running (which I believe is the "R front-end" i see in task manager), but I don't know if it is bad practice to simply include taskkill /IM "Rscript.exe" /F before the line that calls the .wsf file that starts the app.
The main problem I see with this is that if the session is running fine and the user for some reason clicks the app again, it will force a complete restart.
Any suggestions?

R shiny server: how to update scripts with multiple users and sessions?

We run an R shiny server (R: 3.5.1, Shiny: 1.0.3) on a virtual machine under CentOS. We are experiemcing some issues with script updates to the server.
We find that under certain conditions if we update a script to the server it may take some time (up to days occassionally) for the updated script to be actually executed.
From experience, this delay only occurs when the srcipt has multiple users. Scripts that have a sningle user (me) update instantly as soon as the updated scripts have been written to the server.
This makes sense: as long as users are running the scripts in sessions, you cannot update it. We know that resetting the Shniy server does the trick but this strikes me as a crude way of resolving this issue.
As I am not a linux expert I do not know if this is caused by Shiny or by Linux.
Does anyone know where this behaviour is documented so I can learn how to better control the process of updating?

RStudio Server on Microsoft Azure instance

I am currently running R on a Microsoft Azure instance (Ubuntu virtual machine) using RStudio as my IDE, to which I connect simply through my browser. I am trying to run some commands that take quite some time to complete from within RStudio and figured that I could simply close my tab with RStudio open and the process would keep running. However, when I try to reconnect to see how the process is doing, the page keeps loading but I am unable to see RStudio.
I have a few questions regarding running RStudio on a server:
First, am I correct in thinking that I can close my tab and keep the process running?
Second, is it normal behaviour that I am unable to connect to the server while the process is running?
Third, am I going about this the correct way or are there better ways?
Yes, you can close your tab and keep it running.
RStudio Server waits on updates from the R process to update the UI. This means that if you have a long-running computation, your tab may not fully reload until it's finished. You may also have seen this in the middle of a session: when R is busy, you can have problems saving scripts that are open in the editor pane.
Logging out in the middle of a computation should be safe, but be aware that RStudio will save your workspace and shut R down after a period of inactivity. It then reloads everything when you log back in. But this only extends to objects in memory; if you have any files saved in your temp directory, they'll have disappeared when you come back. They're probably still on the disk, but since your new R session has a new temp directory, you'll have to do a manual search for them.

How do you control the lifetime of a Rook server?

I am new to R and to Rook. I am able to successfully run Rook in a browser when I run from RTerm or from RStudio. However, when I run from RScript I get connection refused. My guess is that RScript runs my script and exits the script.
So how would I package up a R Rook application for end users that does not require starting RTerm and manually exiting after the user closes the web pages? Is there a way to handle this using HTTP 1.1 keep alive?
Ahh... It looks like there is an example of doing this. See https://groups.google.com/forum/#!msg/rrook/_da0Xmf8ZWY/SF0k1OvYzGoJ and open the conversation from Sven and download simplerookapp.zip. I have not yet had a chance to verify it, but it does look promising.

Fresh new session for rstudio-server

I am running rstudio-server on a virtualised (vmware-player) ubuntu machine, and processing lots of data into the ram. I find that after some inactivity that the session suspends the data. The problem is that it takes a VERY long time to resume this session and it is making both the host machine and virtual machine lag very badly.
I just want to kill the session and start a new fresh session of rstudio-server, but so far the only way I have found which does this is to reisub my ubuntu machine. Does anyone know a better solution?
As a side note, I think entering session-timeout-minutes=0 in /etc/rstudio/rsession.conf as per here should fix the problem of the session suspending.
I found this page, which deals with resetting the rstudio-desktop version. In my home directory, I found the folder ~/.rstudio. I renamed/deleted this folder and this loads a new rstudio-server instance.
In fact, there is a folder called suspended session in the ~/.rstudio folder, which I suspect is the thing where suspended data is stored, so maybe deleting this folder is sufficient?
If there is a directory inside ~/.rstudio/sessions/active/, deleting it (in the way like rm -rf ~/.rstudio/sessions/active/session-*) might be sufficient to solve the problem.
Your question is a while back but after running into this problem a zilion times i found a way to reset the Rstudio Shiny Server session without the need for admin rights on Rstudio Shiny Server:
put temporarily as first line in server.r :
quit("yes") # FORCE CLOSE OF SESSION server
go to the site and it will crash (the session closes straight away)
delete or comment out:
# quit("yes") # FORCE CLOSE OF SESSION server
go to the site and you will have the shiny app with a new session =^)
Works for me and saves a lot of time searching through all kind of system folders or the need to enter a part of the system that you are not allowed to go or needing admin rights on Rstudio Shiny Server.
I hope this helps.
I have tried the above solutions which didn't work for me. I tried to kill the rsession which is causing the problem. just run this command to find out pid of user session.
ps -u userid
Find out the pid that is causing the rsession to stall. Kill that process and you're good to go.
Note that with newer versions of Rstudio, this folder is now under
~/.local/share/rstudio/sessions/
while in some older versions, it can also be seen in ~/.rstudio-desktop, see documentation page
A quick solution would be to rename ~/.rstudio and reopen the webpage using rstudio url.

Resources