Modular Shiny app workflow in Rstudio - r

While developing a modular Shiny app (with multiple .R files that are sourced by global.R) in RStudio I have to repeatedly
switch to ui.R or server.R
click Run App
click Stop
navigate back the R file I'm working on
Doing this many times is a pain as I hardly work on ui.R or server.R files directly. I've looked for a keyboard shortcut for Run App here to no avail.
Typing runApp() in the Console is a workaround. Anything better?

If your question is just for a shortcut for Run App, ctrl + shift + enter (on windows) works in server.R, ui.R, and app.R files.
Edit: In RStudio you can also use ctrl+f9 and ctrl+f10 to navigate across open tabs and then use ctrl+shift+enter to execute.

Related

Why doesn't anything happen after copying Shiny App files to Shiny Server?

I have encountered problems when trying to upload Shiny apps onto a Shiny Server that is already up and running.
I copied a folder containing the ui.R and server.R files on to the server.
When I try to open the app in the browser by accessing webpage /servername/myUser/folderName, nothing happens. I remain on the front page.
I have tried with several different small example programs, that all run in R when I try.
I also tried to gather my ui.R and server.R to one file "app.R", but the problem persists.
There is another Shiny App on the server, and that one works fine by accessing /servername/otherUser/folderName, so I am not sure what the problem is.
It is the first time I am trying this so it might be something simple that I am overlooking.
I figured it out, the server I was using hadn't installed the packages necessary to run the App.

Run App Option not showing on the Pane, #R

I am learning about shiny dashboards, I am unable to find run app option which comes at the pane where we write our code the run app option is not visible. Kindly assist to enable the same.
For Rstudio to display the run app button, it needs to recognize your script as a shiny app. One of the easiest way in Rstudio would be to go to file --> new file--> Shiny web app, since Rstudio would create the app.R file for you (by now you should see the run app button).
If you are working with a ui.R and server.R file, you should add the following line at the end of your server.R file:
shinyApp(ui = ui, server = server)

runApp() from shiny is not working from code or RStudio's button

I can not run a shiny app, neither by the RStudio's button "Run App" or directly with the code runApp()
I've been using this shiny app for many years. But recently, without any changes, the app stop working when I press the button "Run App" in RStudio. Then I enter the command runApp() and it doesn't work neither.
When I press the RStudio button "Run App" I get:
runApp('')
Error in shinyAppDir(x) : No Shiny application exists at the path ""
When I enter the command shiny::runApp() at the beginning of the app, I get:
Listening on http://127.0.0.1:3642
Warning: Error in runApp: Can't call `runApp()` from within `runApp()`. If your application code contains `runApp()`, please remove it.
51: stop
50: runApp
Error in runApp() :
Can't call `runApp()` from within `runApp()`. If your application code contains `runApp()`, please remove it.
The working directory is good.
So, I'm stuck. I can not run the app.
I just realize that the problem happens when I open RStudio opening the app directly; in this case, RStudio automatically recognizes the working directory as the directory where the app is.
But if I open RStudio first (for example, from the Desktop icon) or the working directory is different from the directory where the app is, I don't have any issue: the "Run App" button in RStudio works perfectly.
I think the button depends on the working directory, if the working directory is different from the app directory, the buttom automatically adds the path so the app can run. But, if the working directory is the same as the app directory, the button removes the path, leaving an empty space inside runApp() and then causing the problem.
I've seen the second error before. I was attempting to solve a different problem when I launched a shiny app. There was a button in it which, on click, had the command runApp to launch another shiny app. That's when I got the error.
A shiny app cannot be called from within another shiny app.
Try adding R file path/ name in runApp command. Example: runApp("test.R")
Create a new R file run.R in the same directory as shiny app. In run.R, type this:
library (shiny)
runApp("test.R")
Run this file like a normal R process.
Instead of runApp, use shinyApp(ui = ui, server = server) in the original shiny app.

Hide R code in shiny executable

I am new to shiny. I have ui and server file. I have packaged my R code, portable R and portable chrome into an executable. I want to distribute the executable to others. How can I hide the R code in ui.r and server.r files?
I want to distribute as desktop app as exe file. So that user should be able to run by just clicking the executable.

After installing shinyapps and shiny, RUN and SOURCE botton disappeared, how to get them back?

I'm using R 3.2 and Rstudio 0.98.953
Just installed shinyapps and shiny, and the RUN APP button showed up (some people say it will only appear in preview version of Rstudio 0.99)
But the RUN and SOURCE botton disappeared. Any way I can get them back? Thanks!
Is the currently open file a file in a Shiny app? If RStudio detects that you're in a Shiny app (the file you're viewing is ui.R or server.R or app.R etc.) then it automatically lets you run the shiny app instead of "run the code" because that's the correct thing to do. When you switch to a different file that's outside of a shiny folder, it should go back to normal.
If you're not inside a Shiny app and it's showing "Run App", then you should file a bug with RStudio

Resources