R
Completed
-
Section 1: Getting Started
-
Section 2: Core Syntax
-
Section 3: Data Structures
-
Section 4: Data Manipulation
-
Section 5: Visualization and Statistics
-
Section 6: Advanced R
-
Section 7: Practical Projects
-
Section 8: Interview Practice
-
Section 9: More Practice Exercises
-
Section 10: Shiny Apps in Depth
-
Section 11: More Data Wrangling
-
Section 12: Tidyverse Deep Dive
-
Section 13: Statistical Modeling Deep Dive
-
Section 14: Machine Learning in R
-
Section 15: R Visualization Deep Dive
-
Section 16: R Package Development Deep Dive
-
Section 17: R for Reproducible Research
-
Section 18: R and Databases
-
Section 19: R Performance Optimization
-
Section 20: Bioinformatics and Specialized R
-
Section 21: More Shiny Practice
-
Section 22: More Practice Exercises
-
Section 23: R Data Structures Deep Dive
-
Section 24: More Interview and Review
-
Section 25: R for Business Analytics
-
Section 26: R Text Mining and NLP
-
Section 27: R Spatial Data Analysis
-
Section 28: R Deep Learning
-
Section 29: Advanced Statistical Techniques
-
Section 30: R Object Systems Deep Dive
-
Section 31: R Environments and Metaprogramming
-
Section 32: R for Finance
-
Section 33: R for Clinical and Health Data
-
Section 34: More Shiny Advanced Practice
-
Section 35: R Data Cleaning Deep Dive
-
Section 36: R Reporting Automation
-
Section 37: More Practical Projects Round 2
-
Section 38: R Ecosystem and Career
-
Section 39: More Visualization Practice
-
Section 40: R for Experimentation
-
Section 41: R for Genomics and Bioinformatics Deep Dive
-
Section 42: R for Marketing Analytics
-
Section 43: R Data Import/Export Deep Dive
-
Section 44: R String Processing Deep Dive
-
Section 45: R for Actuarial and Insurance Analytics
-
Section 46: R Testing and Quality Assurance Deep Dive
-
Section 47: R Version Control and Collaboration
-
Section 48: R Advanced Functional Programming
-
Section 49: R for Supply Chain and Operations
-
Section 50: More Practice Exercises Round 3
-
Section 51: R Dashboards and BI Integration
-
Section 52: R Data Governance and Ethics
-
Section 53: More Modeling Practice
-
Section 54: R Final Capstone Projects
-
Section 55: R for Sports Analytics
-
Section 56: More Interview Practice Round 2
-
Section 57: R Networking and APIs
-
Section 58: R for Environmental Science
-
Section 59: R Notebook and Documentation Practices
-
Section 60: More Data Wrangling Mastery
-
Section 61: R for A/B Testing at Scale
-
Section 62: R Package Ecosystem Deep Dive
45: Deploying a Shiny App
I've seen this happen a dozen times: a developer spends three days polishing a beautiful Shiny dashboard, clicks "Publish," and then spends the next six hours staring at a "Disconnected from Server" error or a cryptic Error: package 'plotly' not found. They usually tell me, "But it works perfectly on my laptop!"
The "Just Upload the Script" Fallacy
The biggest misconception I encounter is the belief that a Shiny app is just a script. You think that because you have the app.R file, you have the whole application. In reality, your app is a fragile ecosystem that relies on a specific version of R, a specific set of libraries, and—most dangerously—a specific folder structure on your hard drive.
Let's say you have an app that reads a sales dataset from C:/Users/Sarah/Documents/Project/data/sales_2023.csv. When you deploy that to a Linux-based server like shinyapps.io, the server is going to look for a folder called "Users" in its root directory, fail to find it, and crash your app instantly. The server doesn't know who "Sarah" is, and it certainly doesn't have access to your Documents folder.
Creating a Portable Application Environment
To fix this, you have to stop thinking about your app as a file and start thinking about it as a package. First, you must use relative paths. I always tell my juniors: if you see a drive letter (like C:) or a home directory tilde (~) in your code, your app is already broken for deployment.
Instead, keep your data in a subfolder within your app directory and call it like this:
# Wrong
data <- read.csv("C:/Users/Sarah/Project/data/sales_2023.csv")
# Right
data <- read.csv("data/sales_2023.csv")
Next, we have to handle the dependencies. You can't assume the server has the same libraries you've spent months installing. While the rsconnect package does a decent job of detecting library() calls, I highly recommend using renv. It creates a lockfile that explicitly tells the server, "I need plotly version 4.10.1, not just any version of plotly." It saves you from the nightmare of your app breaking because a package updated overnight.
Navigating the Deployment Pipeline
Depending on who is paying for the hosting, you'll usually land in one of two places: shinyapps.io or a private Shiny Server/Posit Connect instance. For most of us, shinyapps.io is the starting point because it removes the need to manage a Linux server.
When you use deployApp(), RStudio isn't just uploading your script; it's bundling your files and sending them to a container. I've found that the most common "silent killer" during this process is memory. If your app loads a 2GB CSV into RAM on your 32GB workstation, it'll fly. But the free tier of many hosting services might only give you 1GB of RAM. If your app exceeds that, the server will simply kill the process without telling you why. If your app is crashing on deploy but working locally, check your data size first.
📋 Practical Task
Fixing the "Broken Path" Sales Dashboard
You have been handed a Shiny app called sales_dashboard.R that works on the previous developer's machine but fails immediately upon deployment. Your goal is to make this app "deployment-ready."
The Setup:
The app currently contains the following line:
df <- read.csv("C:/Users/DevUser/Desktop/Analytics/current_quarter_sales.csv").
The CSV file has been moved into a folder named data which is located in the same directory as the app.R file.
Your Task:
- Modify the data loading line to use a relative path so the app can find the CSV regardless of which server it is hosted on.
- Wrap the data loading process in a
tryCatch()block to provide a user-friendly error message in the UI if the file is missing, rather than letting the app crash. - Identify and list the three specific dependencies (packages) used in the script and create a mock
renv.locklogic (or a simpleinstall.packages()script) that ensures a fresh server environment would have them installed before the app launches.
There are no comments for now.