Push Button Publishing for Shiny Apps
Tags: shiny, rstats
Published: 2021-05-17 17:16:15

<p><em>By: <a href='https://hosting.analythium.io/author/peter/'>Peter Solymos</a></em></p><p>In a previous post you saw how to <a href="https://hosting.analythium.io/run-shiny-apps-locally/">run Shiny apps locally</a>. Certain use cases need to be run locally, most web applications deserve to be hosted on the web. The official <a href="https://shiny.rstudio.com/deploy/">Shiny documentation</a> on the RStudio website offers 3 ways of putting Shiny applications on the web:</p><ol><li><strong>Shinyapps.io</strong>: free or paid cloud hosting with push button publishing</li><li><strong>RStudio Connect</strong>: paid self hosted option for authoring Shiny apps among many other things with push button or git based publishing</li><li><strong>Shiny Server</strong>: free self hosted option with file transfer based publishing (the paid Pro version is discontinued in favour of RStudio Connect)</li></ol><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://hosting.analythium.io/content/images/2021/04/Screen-Shot-2021-04-02-at-8.23.19-PM.png" class="kg-image" alt="Official deployment options for Shiny by RStudio" loading="lazy" width="1856" height="1356" srcset="https://hosting.analythium.io/content/images/size/w600/2021/04/Screen-Shot-2021-04-02-at-8.23.19-PM.png 600w, https://hosting.analythium.io/content/images/size/w1000/2021/04/Screen-Shot-2021-04-02-at-8.23.19-PM.png 1000w, https://hosting.analythium.io/content/images/size/w1600/2021/04/Screen-Shot-2021-04-02-at-8.23.19-PM.png 1600w, https://hosting.analythium.io/content/images/2021/04/Screen-Shot-2021-04-02-at-8.23.19-PM.png 1856w" sizes="(min-width: 720px) 720px"><figcaption>Official deployment options for Shiny by RStudio</figcaption></figure><p>Push button publishing is available for Shinyapps.io and RStudio Connect from the RStudio IDE (desktop or server edition) or from any R console using the <a href="https://cran.r-project.org/package=rsconnect">rsconnect</a> R extension package.</p><h2 id="shinyappsio">Shinyapps.io</h2><p>Shinyapps.io is the easiest and quickest way for sharing Shiny apps with the world. Apps are hosted in the cloud on shared servers operated by RStudio. Apps are self contained and isolated from each other. Connections are encrypted (HTTPS) by default. </p><figure class="kg-card kg-bookmark-card"><a class="kg-bookmark-container" href="https://hosting.analythium.io/the-anatomy-of-a-shiny-application/"><div class="kg-bookmark-content"><div class="kg-bookmark-title">The Anatomy of a Shiny Application</div><div class="kg-bookmark-description">Shiny lets you quickly build web applications using the R programming language. In this post I will walk you through how a Shiny application is structured. The goal is simply to have the most basic and dependency free app that we can deploy. Let’s get going!</div><div class="kg-bookmark-metadata"><img class="kg-bookmark-icon" src="https://hosting.analythium.io/assets/icon-192x192.png?v&#x3D;fd473cce31"><span class="kg-bookmark-author">Hosting Data Apps</span><span class="kg-bookmark-publisher">Peter Solymos</span></div></div><div class="kg-bookmark-thumbnail"><img src="https://hosting.analythium.io/content/images/2021/04/3-blank-2.png"></div></a></figure><p>To be able to take advantage of push button publishing from RStudio IDE, complete the following prerequisites:</p><ul><li>Install a recent version of <a href="https://www.rstudio.com/products/rstudio/download/">RStudio IDE</a></li><li>Install R and the rsconnect R package ( <code>install.packages("rsconnect")</code>)</li><li>Create a <a href="http://www.shinyapps.io/">Shinyapps.io</a> account</li><li><a href="https://docs.rstudio.com/shinyapps.io/getting-started.html#configure-rsconnect">Configure rsconnect</a> using a token</li></ul><p>The following image gallery shows how to deploy the <a href="https://gitlab.com/analythium/shinyproxy-hello/">Hello app</a> to the Shinyapps.io service:</p><ol><li>Open up the project in RStudio IDE, click the Publish button at the top of the file editor pane then click Publish Application</li><li>Select the account you wish to deploy to if you set up multiple accounts, name the app (here we use 'hello'), and select what files to deploy as part of the app</li><li>Wait until the deployment is complete, you can follow the process in the Deploy pane</li><li>The browser is launched with the new deployment by default, check that everything works as expected</li></ol><figure class="kg-card kg-gallery-card kg-width-wide kg-card-hascaption"><div class="kg-gallery-container"><div class="kg-gallery-row"><div class="kg-gallery-image"><img src="https://hosting.analythium.io/content/images/2021/05/Screen-Shot-2021-05-07-at-11.51.26-PM.png" width="1276" height="586" loading="lazy" alt srcset="https://hosting.analythium.io/content/images/size/w600/2021/05/Screen-Shot-2021-05-07-at-11.51.26-PM.png 600w, https://hosting.analythium.io/content/images/size/w1000/2021/05/Screen-Shot-2021-05-07-at-11.51.26-PM.png 1000w, https://hosting.analythium.io/content/images/2021/05/Screen-Shot-2021-05-07-at-11.51.26-PM.png 1276w" sizes="(min-width: 720px) 720px"></div><div class="kg-gallery-image"><img src="https://hosting.analythium.io/content/images/2021/05/Screen-Shot-2021-05-07-at-11.53.40-PM.png" width="2000" height="1277" loading="lazy" alt srcset="https://hosting.analythium.io/content/images/size/w600/2021/05/Screen-Shot-2021-05-07-at-11.53.40-PM.png 600w, https://hosting.analythium.io/content/images/size/w1000/2021/05/Screen-Shot-2021-05-07-at-11.53.40-PM.png 1000w, https://hosting.analythium.io/content/images/size/w1600/2021/05/Screen-Shot-2021-05-07-at-11.53.40-PM.png 1600w, https://hosting.analythium.io/content/images/size/w2400/2021/05/Screen-Shot-2021-05-07-at-11.53.40-PM.png 2400w" sizes="(min-width: 720px) 720px"></div></div><div class="kg-gallery-row"><div class="kg-gallery-image"><img src="https://hosting.analythium.io/content/images/2021/05/Screen-Shot-2021-05-07-at-11.57.59-PM.png" width="2000" height="1277" loading="lazy" alt srcset="https://hosting.analythium.io/content/images/size/w600/2021/05/Screen-Shot-2021-05-07-at-11.57.59-PM.png 600w, https://hosting.analythium.io/content/images/size/w1000/2021/05/Screen-Shot-2021-05-07-at-11.57.59-PM.png 1000w, https://hosting.analythium.io/content/images/size/w1600/2021/05/Screen-Shot-2021-05-07-at-11.57.59-PM.png 1600w, https://hosting.analythium.io/content/images/size/w2400/2021/05/Screen-Shot-2021-05-07-at-11.57.59-PM.png 2400w" sizes="(min-width: 720px) 720px"></div><div class="kg-gallery-image"><img src="https://hosting.analythium.io/content/images/2021/05/Screen-Shot-2021-05-07-at-11.57.37-PM.png" width="2000" height="1555" loading="lazy" alt srcset="https://hosting.analythium.io/content/images/size/w600/2021/05/Screen-Shot-2021-05-07-at-11.57.37-PM.png 600w, https://hosting.analythium.io/content/images/size/w1000/2021/05/Screen-Shot-2021-05-07-at-11.57.37-PM.png 1000w, https://hosting.analythium.io/content/images/size/w1600/2021/05/Screen-Shot-2021-05-07-at-11.57.37-PM.png 1600w, https://hosting.analythium.io/content/images/2021/05/Screen-Shot-2021-05-07-at-11.57.37-PM.png 2222w" sizes="(min-width: 720px) 720px"></div></div></div><figcaption>Steps to deploy the hello app to Shinyapps.io / © Analythium</figcaption></figure><p>Your newly deployed app will be available at https://username.shinyapps.io/appname. The dashboard in your Shinyapps.io account will list the 'hello' app. Click on the app to see usage statistics and <a href="https://docs.rstudio.com/shinyapps.io/applications.html">settings</a>. This is the place where you can archive or delete the app too.</p><figure class="kg-card kg-gallery-card kg-width-wide kg-card-hascaption"><div class="kg-gallery-container"><div class="kg-gallery-row"><div class="kg-gallery-image"><img src="https://hosting.analythium.io/content/images/2021/05/Screen-Shot-2021-05-07-at-11.58.43-PM-1.png" width="2000" height="919" loading="lazy" alt srcset="https://hosting.analythium.io/content/images/size/w600/2021/05/Screen-Shot-2021-05-07-at-11.58.43-PM-1.png 600w, https://hosting.analythium.io/content/images/size/w1000/2021/05/Screen-Shot-2021-05-07-at-11.58.43-PM-1.png 1000w, https://hosting.analythium.io/content/images/size/w1600/2021/05/Screen-Shot-2021-05-07-at-11.58.43-PM-1.png 1600w, https://hosting.analythium.io/content/images/size/w2400/2021/05/Screen-Shot-2021-05-07-at-11.58.43-PM-1.png 2400w" sizes="(min-width: 720px) 720px"></div><div class="kg-gallery-image"><img src="https://hosting.analythium.io/content/images/2021/05/Screen-Shot-2021-05-08-at-12.52.17-AM-1.png" width="2000" height="1053" loading="lazy" alt srcset="https://hosting.analythium.io/content/images/size/w600/2021/05/Screen-Shot-2021-05-08-at-12.52.17-AM-1.png 600w, https://hosting.analythium.io/content/images/size/w1000/2021/05/Screen-Shot-2021-05-08-at-12.52.17-AM-1.png 1000w, https://hosting.analythium.io/content/images/size/w1600/2021/05/Screen-Shot-2021-05-08-at-12.52.17-AM-1.png 1600w, https://hosting.analythium.io/content/images/2021/05/Screen-Shot-2021-05-08-at-12.52.17-AM-1.png 2396w" sizes="(min-width: 720px) 720px"></div></div></div><figcaption>Application settings and monitoring in the Shinyapps.io dashboard</figcaption></figure><p>The <code>deployApp()</code> command from the rsconnect package is used in the background to deploy the app to Shinyapps.io. The command works from the command line to initially deploy and later to redeploy the app.</p><p>Keep in mind that Shinyapps.io is a managed service and comes with some limitations regarding dependencies: required R packages need to be able to run on Ubuntu Linux and cannot rely on graphical display only (Tcl/Tk). Installing packages from Bioconductor needs the <a href="https://docs.rstudio.com/shinyapps.io/getting-started.html#using-your-r-packages-in-the-cloud">repositories set</a> by <code>setRepositories()</code>. If a package has missing system dependencies, you can find available system packages <a href="https://docs.rstudio.com/shinyapps.io/appendix.html#default-system-packages">here</a>, or file an issue <a href="https://github.com/rstudio/shinyapps-package-dependencies">here</a>.</p><h2 id="rstudio-connect">RStudio Connect</h2><p>Push button publishing to RStudio Connect works very similarly to the previously described process. The only difference is the <a href="https://docs.rstudio.com/connect/user/connecting/">publishing account setup</a>. In the RStudio IDE, click the Tools menu item, select Global Options from the dropdown, then click Publishing in the left navigation of the popup window. Now click the Connect button and <a href="https://docs.rstudio.com/connect/user/publishing/">follow the prompts</a>. If your app needs specific dependencies, talk to your <a href="https://docs.rstudio.com/connect/admin/r/package-management/">system administrator</a>.</p><p><em>Note: publishing with RStudio Connect requires you or your organization to have a server running RStudio Connect with a valid license.</em></p><h2 id="further-reading">Further reading</h2><ul><li><a href="https://docs.rstudio.com/shinyapps.io/">Shinyapps.io user guide</a></li><li><a href="https://community.rstudio.com/tags/shinyappsio">Shinyapps.io category on RStudio Community</a></li><li>RStudio Connect <a href="https://docs.rstudio.com/connect/user/">user</a> and <a href="https://docs.rstudio.com/connect/admin/">administration</a> guides</li><li><a href="https://support.rstudio.com/hc/en-us/articles/217240558-What-is-the-difference-between-shinyapps-io-and-Shiny-Server-Pro-">Difference between RStudio Connect and Shinyapps.io</a></li></ul><p><em>RStudio and Shiny are trademarks of RStudio, PBC</em></p>