[This article was first published on rdata.lu Blog | Data science with R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Hello everyone,

Why we always want to take the red pill when we can take the blue one? That’s the question!
In this post I will explain how to launch a shiny application from a shortcut. Just like that:

It’s fast and useful if you work with colleagues that don’t have a clue about R and just want to use your shiny app.

#### If you are on macOS:

Open a text editor and write the following lines :

 Rscript '&FullPath/&file.R' &
open http://127.0.0.1:&PortNumber/;

& allows you to write more command lines even if the shell is still busy with the previous line. The second line opens your web browser with the chosen address. A concrete example gives this:

Rscript '/Users/user/Desktop/Clef_USB/data_science/fret_dashboard.R' &
open http://127.0.0.1:7990/;

On the second line, 7990 refers to the chosen port in your shiny app. If you didn’t choose one, add the following to your shinyApp: options = list(port= 7990), just like that:
shinyApp(ui=ui,server=server, options = list(port=7990))

If you use a .Rmd document, you should write this:

 Rscript -e  "rmarkdown::run('&FullPath/&file.Rmd', shiny_args = list(port=&PortNumber))" &
open http://127.0.0.1:&PortNumber/&file.Rmd;

Replace &FullPath, &file and &PortNumber by the file path, the file name and the chosen port.

Then save it with the “.command” extension and try to launch your shiny application from the shortcut. If you have a message saying that the file could not be executed because you do not have appropriate access privileges, open your terminal and write the following line:

chmod u+x &FullPath/&file.command

Then it should work 🙂
We are almost done, now we have to add another shortcut icon to make it look more friendly. For that, go on google and download free .icns icons. I have download some icons on easyicon. To change the icon you just need to go in “get info” and drag your new icon to the previous one, just like below:

#### If you are on Windows:

Open a text editor and write the following lines:

start "" "&FullPath1\Rscript.exe" &FullPath2\&file.R  /k
start "Name" "http://127.0.0.1:&PortNumber/"

/k allows you to write something in the command prompt even if the Prompt is busy with the previous line. A concrete example gives that :

start "" "C:\Program Files\R\R-3.3.3\bin\Rscript.exe" C:\Users\CGP462\Documents\Shiny_app\iris.R  /k
start "iris" "http://127.0.0.1:7924/"

Then you can save your file with a .bat extension.
Be carefull, if you want to launch a .Rmd you should use this code instead :

start "&FullPath1\R.exe" -e "Sys.setenv(RSTUDIO_PANDOC='C:/Program Files/RStudio/bin/pandoc'); rmarkdown::run('&FullPath2/&file.Rmd', shiny_args = list(port =&PortNumber, launch.browser = FALSE))" /k
start "&file" "http://127.0.0.1:7924/&file.Rmd"

if it doesn’t work, check your pandoc location.

It’s almost done. Now we have to change the icon. First you have to download an icon with the .ico extension. Then you have to act in 4 steps :
1. Right click on your file and go in Properties.
2. Choose the Shortcut tab.
3. Then go in Change Icon….
4. In Browse, select the icon you want to see instead.

And now it’s done!

Don’t hesitate to follow us on twitter @rdata_lu and to subscribe to our youtube channel.
You can also contact us if you have any comments or suggestions. See you for the next post!

To leave a comment for the author, please follow the link and comment on their blog: rdata.lu Blog | Data science with R.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

# Never miss an update! Subscribe to R-bloggers to receive e-mails with the latest R posts.(You will not see this message again.)

Click here to close (This popup will not appear again)