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' &
& 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' &
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))" &
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:
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!