How to Share R Shiny Apps - Top 3 Methods Explained

Estimated time:

Let’s face the facts - you want your amazing dashboards seen by the world. To do so, you have to find a way to share R Shiny apps. There are numerous ways you can approach this, from sharing your code as a zip file to Docker images. We’ll cover a few of the possibilities today, and leave edge cases for some other time. <blockquote>Interested in R beyond Shiny? <a href="" target="_blank" rel="noopener noreferrer">Learn to make PowerPoint presentations with R Markdown</a>.</blockquote> Table of contents: <ul><li><a href="#basic-shiny-app">Let’s Code a Basic R Shiny App</a></li><li><a href="#github">How to Share R Shiny Apps on GitHub</a></li><li><a href="#shinyappsio"> - Share your R Shiny Apps for Free</a></li><li><a href="#shiny-server">Shiny Server - If You Want To Do It Yourself</a></li><li><a href="#conclusion">Conclusion</a></li></ul> <hr /> <h2 id="basic-shiny-app">Let’s Code a Basic R Shiny App</h2> This section should feel easy even if you know nothing about R Shiny. We’ll create a simple web application that lets users enter their names, and Shiny then greets them with a custom <em>hello</em> message. Think of it as a “Hello World” for R Shiny. Open <a href="" target="_blank" rel="noopener noreferrer">RStudio</a> and create a new file called app.R. Then paste the following code: <script src=""></script> Here’s what you’ll see once you run the app: <img class="size-full wp-image-12155" src="" alt="Image 1 - “Hello World” R Shiny app" width="906" height="712" /> Image 1 - “Hello World” R Shiny app To recap, the app has a single input and a single output element, and both are text-based. It’s nothing to write home about but will serve us just fine to explore sharing options. We have a solution if you want something more advanced, but don't have the time to build it. You can download several of <a href="" target="_blank" rel="noopener noreferrer">Appsilon's Shiny Templates</a> for free. Then you can customize your new Shiny templates in less than 10 minutes with our <a href="" target="_blank" rel="noopener noreferrer">guide on developing Shiny dashboards</a>. <h2 id="github">How to Share R Shiny Apps on GitHub</h2> You have two options if you want to share R Shiny apps through GitHub: <ol><li><strong>As a repository</strong> - Recommended approach, especially if your app is broken into multiple files. The best practice is to include a readme file to instruct the reader on how to get started.</li><li><strong>As a gist</strong> - Only for a single-file R Shiny apps, like ours is. You can load the Shiny application directory from a GitHub gist in R.</li></ol> There are other, more advanced options, such as GitHub actions, but it’s out of the scope for today’s article. Our app only has a single file (<code>app.R</code>), so let’s proceed with gists. Log in to your GitHub account and select a <em>New Gist</em> option under the plus sign in the top right corner. Add the name and code to the gist: <img class="size-full wp-image-12147" src="" alt="Image 2 - Creating a new GitHub gist" width="2122" height="1226" /> Image 2 - Creating a new GitHub gist Change the bottom dropdown value to “Create public gist” and click on that button. Your gist will be created immediately. The URL will have the following structure: <code>;your_username&gt;/&lt;gist_id&gt;</code>. The last part (<code>&lt;gist_id&gt;</code>) is all we need. Create a new R file in RStudio and paste the following code: <script src=""></script> Of course, you should replace the value in <code>runGist()</code> with your gist ID. Once done hit CTRL/CMD + Enter to run the code line: <img class="size-full wp-image-12159" src="" alt="Image 3 - Running an R Shiny app from a GitHub gist" width="3012" height="1856" /> Image 3 - Running an R Shiny app from a GitHub gist And there you have it. It's pretty basic and limited but works for simple apps. The major downsides are that other users are assumed to have R and RStudio installed, and you can only share single-file Shiny apps this way. The next option to share R Shiny apps addresses these shortcomings. <h2 id="shinyappsio"> - Share your R Shiny Apps for Free</h2> The term “free” is open for debate. You can host your Shiny apps free of charge as long as you have 5 or fewer applications and don’t need more than 25 active hours. If you need to scale, the paid plans start at <a href="" target="_blank" rel="noopener noreferrer">$9 per month</a>. The free plan is enough to serve our needs. You’ll have to register for a free account first. Use your Google or GitHub credentials to shorten the process. Once done, you’ll have to install the <code>rsconnect</code> package from the R console and authenticate through it. The authentication details (name, token, and secret key) are listed on the shinyapps dashboard page: <script src=""></script> From the console, import the <code>rsconnect</code> package and call the <code>deployApp()</code> function as shown below: <script src=""></script> The deployment process might take a minute. Here’s what you should see printed to the console: <img class="size-full wp-image-12151" src="" alt="Image 4 - Deploying a Shiny app to" width="1518" height="582" /> Image 4 - Deploying a Shiny app to The good news? The app will open automatically once deployed. Here’s what it looks like on our end: <img class="size-full wp-image-12149" src="" alt="Image 5 - Deployed R Shiny app on" width="2394" height="1932" /> Image 5 - Deployed R Shiny app on It looks identical to the one running locally, but the URL tells us that we’re looking at the deployed version. You can now share this URL with anyone and they can easily interact with your app! But can we take it a step further? Yes, by managing the entire server on our own. Let’s see how. <h2 id="shiny-server">Shiny Server - A DIY Approach</h2> Setting up <a href="" target="_blank" rel="noopener noreferrer">Shiny Server</a> from scratch can be tricky when doing it the first time. There’s an open-source version available, but it implies a from-scratch setup and configuration on a remote server. Yes, you’ll need a server. We’ve chosen the free <a href="" target="_blank" rel="noopener noreferrer">EC2 Ubuntu instance</a> on Amazon AWS. From this point, we assume you’ve provisioned a computing instance and connected to it over SSH: <img class="size-full wp-image-12153" src="" alt="Image 6 - EC2 AWS instance" width="2770" height="1450" /> Image 6 - EC2 AWS instance Once inside, there are a couple of commands you’ll have to run: <script src=""></script> Running these will take a couple of minutes at least, but once done you’ll see that the Shiny Server service is running: <img class="size-full wp-image-12163" src="" alt="Image 7 - Shiny Server status on an EC2 instance" width="2770" height="1450" /> Image 7 - Shiny Server status on an EC2 instance You can examine the server configuration files through the Terminal or by connecting via a text editor, such as Visual Studio Code. The file under <code>/etc/shiny-server/shiny-server.conf</code> tells us everything we need to deploy the app: <img class="size-full wp-image-12161" src="" alt="Image 8 - Shiny server configuration file" width="2662" height="2018" /> Image 8 - Shiny server configuration file The Shiny Server is located under <code>/src/shiny-server</code>, and it’s running on port 3838. That’s a problem since only port 22 is accessible from anywhere. You’ll need to change the inbound rules of the EC2 instance before proceeding. Open your instance details on AWS, click on the <em>Security</em> tab and click on the security group. You’ll see <em>Inbound rules</em> at the bottom, so click on <em>Edit inbound rules</em>. Add a new rule according to the second list item in the following image: <img class="size-full wp-image-12145" src="" alt="Image 9 - Adding a new inbound rule for port 3838" width="2692" height="1904" /> Image 9 - Adding a new inbound rule for port 3838 That’s all you have to do configuration-wise. Now copy your local Shiny app to <code>/srv/shiny-server/&lt;app-folder-name&gt;</code>. We’ve named our folder <code>myshinyapp</code> and it contains a single <code>app.R</code> file. <blockquote>Interested in R Shiny? <a href="" target="_blank" rel="noopener noreferrer">Make it your career in 2022 by following our detailed guide</a>.</blockquote> You can now finally open your Shiny app. The URL structure is as follows: <code>&lt;instance_ipv4&gt;:3838/&lt;app-folder-name&gt;</code>: <img class="size-full wp-image-12157" src="" alt="Image 10 - R Shiny app running on an EC2 instance" width="2554" height="2000" /> Image 10 - R Shiny app running on an EC2 instance And there you have it - the app is successfully running on a remote computing instance. It took us a while to configure the server, but it’s now running completely free of charge on a free EC2 instance. <hr /> <h2 id="conclusion">Conclusion</h2> Sharing R Shiny applications can be a daunting task for beginners. Sure, you can upload a gist to GitHub, but that’s not enough if you want to share the app with non-technical users. We’ve explored two alternatives - one free (to a degree) with almost no setup and the other that’s also free but requires you to set up a cloud compute instance and configure everything yourself. You can’t go wrong with either. The latter offers the most customizability but is also the most difficult to manage. Now if you're sharing a Shiny app for enterprise purposes, you'll want something a little more robust. If you need assistance here, <a href="" target="_blank" rel="noopener noreferrer">Appsilon</a> is an <a href="" target="_blank" rel="noopener noreferrer">RStudio Full Service Certified Partner</a>. We develop advanced R Shiny applications for Fortune 500 companies across the globe. We'd be happy to help you choose the right options for your use case. <em>What is your preferred way to share R Shiny apps?</em> Please let us know in the comment section below.

Contact us!
Damian's Avatar
Damian Rodziewicz
Head of Sales
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Have questions or insights?
Engage with experts, share ideas and take your data journey to the next level!
Join Slack
Explore Possibilities

Take Your Business Further with Custom Data Solutions

Unlock the full potential of your enterprise with our data services, tailored to the unique needs of Fortune 500 companies. Elevate your strategy—connect with us today!

Talk to our Experts
deploy shiny apps
shiny dashboards