So, you've built an awesome interactive Shiny app, and now you want to share it with the world. Great! Deploying your app might sound intimidating, but with Quarto and the rsconnect
package, it's surprisingly straightforward. This guide will walk you through the entire process, from installation to launch.
Let's get your app live!
Step 1: Install Quarto
First things first, you need Quarto on your machine. Quarto is an open-source scientific and technical publishing system that works beautifully with R, Python, and more. It's the engine that will help package your app for the web.
- Action: Head over to the official Quarto download page.
- Download the appropriate installer for your operating system (Windows, macOS, or Linux) and run it. The setup wizard is simple and will handle everything for you.
Step 2: Restart RStudio
This step is simple but crucial. After installing Quarto, RStudio needs a complete refresh to recognize that it's there. Don't just close the window—quit the entire application and open it again.
- Action: Close RStudio completely and then relaunch it. This ensures that the "Render" button and other Quarto integrations appear correctly.
Step 3: Get the rsconnect
Library
The rsconnect
package is the magic wand that connects your local R session to your shinyapps.io account. It handles the authentication and the process of bundling and uploading your app's files.
- Action: Open your RStudio console and run the following command to install the package from CRAN:
install.packages('rsconnect')
Step 4: Connect and Deploy!
You're at the final step! It's time to connect your RStudio to your shinyapps.io account and send your app to the server.
A. Connect Your Account
You'll need to authenticate your session with a unique token and secret from your shinyapps.io account.
- Find Your Credentials:
- Log in to your shinyapps.io account.
- Click on your name/profile icon in the top right corner and go to Tokens.
- Click "+ Add Token" to generate a new set of credentials.
- Click "Show" and copy the token and secret. Keep these private!
- Action: Now, run the following code in your RStudio console, replacing the placeholders with your actual name, token, and secret.
# Load the library
library(rsconnect)
# Configure your account -- replace with your own info!
rsconnect::setAccountInfo(name='your-account-name',
token='YOUR_TOKEN_HERE',
secret='YOUR_SECRET_HERE')
B. Deploy the App
With your account configured, you can now deploy your app with a single command. Just point the deployApp()
function to the directory containing your Shiny app's files (e.g., app.R
or ui.R
and server.R
).
- Action: Run the command below, making sure to replace the example file path with the actual path to your app's folder.
# Deploy the app from its directory
rsconnect::deployApp('C:/path/to/your/MyShinyApp')
RStudio will now bundle your application, show the deployment progress in the console, and open your newly published app in a web browser when it's done.
And that's it! Your Shiny app is now live on the web for anyone to see. Happy coding! ✨
Post a Comment