Building Scalable Web Apps
A Shiny app running on your laptop is only useful to you. This final lesson covers taking your app from localhost to a live, publicly accessible production deployment.
1. Testing Locally First
# In RStudio, with app.R open:
shiny::runApp("path/to/your/app")
# Or simply click "Run App" in the RStudio toolbar
2. Deployment Option Overview
| Platform | Best For | Cost |
|---|---|---|
| shinyapps.io | Quick deployment, small-to-medium apps | Free tier + paid plans |
| Shiny Server (Open Source) | Self-hosted on your own Linux server | Free (you manage the server) |
| Posit Connect | Enterprise deployment with access control | Paid, enterprise-focused |
| Docker container | Portable deployment to any cloud (AWS, GCP, Azure) | Depends on hosting |
3. Deploying to shinyapps.io (Fastest Path)
Step 1: Create an Account
Sign up for free at shinyapps.io.
Step 2: Install and Configure rsconnect
install.packages("rsconnect")
library(rsconnect)
# Copy your token/secret from the shinyapps.io dashboard
rsconnect::setAccountInfo(name = "your-account-name",
token = "YOUR_TOKEN",
secret = "YOUR_SECRET")
Step 3: Deploy Your App
rsconnect::deployApp("path/to/your/app")
RStudio will upload your app, install required packages in the cloud, and give you a live public URL like https://your-account.shinyapps.io/your-app/.
Common Issues: Never hardcode API keys, database passwords, or secrets directly in app.R when deploying. Use environment variables set through the deployment platform's dashboard instead.
4. Setting Up Your Own Shiny Server (Linux)
# On an Ubuntu server
sudo apt-get install gdebi-core
wget https://download3.rstudio.org/ubuntu-18.04/x86_64/shiny-server-1.5.20.1002-amd64.deb
sudo gdebi shiny-server-1.5.20.1002-amd64.deb
# Place your app in the default directory
sudo cp -R my_shiny_app /srv/shiny-server/
# Access it at http://your-server-ip:3838/my_shiny_app/
5. Managing Dependencies for Deployment
Use renv to lock exact package versions so your deployed app behaves identically to your local development environment:
install.packages("renv")
renv::init() # creates a project-local library and lockfile
renv::snapshot() # records exact package versions in renv.lock
6. Performance Tips for Production Apps
- Use
reactive()andeventReactive()to avoid redundant recalculation. - Pre-aggregate large datasets outside the app where possible, rather than on every reactive trigger.
- Enable caching with
bindCache()for expensive, repeatable computations (Shiny 1.6+). - Monitor app logs on shinyapps.io or Shiny Server for errors and slow response times.
7. Production-Ready Checklist
- ✅ Test thoroughly locally — before deploying anywhere.
- ✅ Choose the right platform — shinyapps.io for speed, Shiny Server for full control.
- ✅ Lock dependencies with renv — for consistent, reproducible deployments.
- ✅ Never hardcode secrets — use environment variables instead.
- ✅ Optimize reactivity — for a smooth experience under real user load.
Pro Tip: Congratulations — you've gone from installing R to deploying a live, interactive web application. That end-to-end journey is exactly what separates a hobbyist from a production-ready R developer.
PreviousDynamic Reporting with R Markdown and Knitr
Next You've reached the end!
Ready to master R Programming?
Build real-world data analysis and visualization projects with hands-on training, mentor-led sessions, and placement support.
.png)