Introduction
Shinylive enables you to run Shiny applications entirely in the browser using WebAssembly. In this advanced tutorial, we explore techniques to fine-tune your Shinylive deployment by managing assets, handling multiple applications, and troubleshooting common issues. These advanced methods will help you create robust, serverless Shiny apps that are easy to maintain and deploy.
1. Asset Management
Efficient asset management ensures your Shinylive app runs smoothly. The {shinylive}
package handles web assets (HTML, JavaScript, CSS, and WASM files) required for serverless Shiny.
Checking Asset Information
Use the following command to check installed asset versions and cache paths:
::assets_info() shinylive
This command returns details such as the Shinylive R package version, the asset version, and the local cache directory.
Downloading and Updating Assets
To manually download a specific version of the assets (if needed), run:
::assets_download("0.1.5") shinylive
Replace "0.1.5"
with the desired version.
Cleaning Up Old Assets
Over time, your cache may accumulate outdated assets. Clean them up using:
::assets_cleanup() shinylive
Or remove a specific version:
::assets_remove("0.1.5") shinylive
Regularly cleaning up assets can help avoid conflicts and save disk space.
2. Handling Multiple Applications
If you have several Shiny applications, you can export them into subdirectories so they share the same Shinylive assets. This is useful for creating a centralized static site for multiple apps.
Example: Exporting Multiple Apps
Assume you have two Shiny apps located in myapp1
and myapp2
. You can export them as follows:
::export("myapp1", "site", subdir = "app1")
shinylive::export("myapp2", "site", subdir = "app2") shinylive
This command creates separate folders (e.g., site/app1
and site/app2
) within your exported site, sharing the common Shinylive assets.
Organizing multiple apps in subdirectories simplifies maintenance and allows you to manage shared assets efficiently.
3. Troubleshooting Common Issues
Even with a robust setup, you may encounter issues when deploying Shinylive apps. Here are some common troubleshooting steps:
Missing or Outdated Assets
- Symptom: Your app fails to load or displays errors related to missing JavaScript or WASM files.
- Solution:
- Run
shinylive::assets_info()
to verify installed versions.
- If assets are missing or outdated, use
shinylive::assets_download()
to update them.
- Run
Export Problems
- Symptom: The export process fails or the output directory does not contain expected files.
- Solution:
- Ensure that your Shiny app is functioning locally before exporting.
- Double-check that the directory paths in your export command are correct.
- Perform a clean rebuild using
quarto clean
if integrated with Quarto.
- Ensure that your Shiny app is functioning locally before exporting.
Deployment Issues
- Symptom: The exported app works locally but fails when deployed to a static hosting service.
- Solution:
- Verify that your hosting service is correctly configured to serve static files.
- Ensure that all asset paths are relative and that the directory structure is maintained during deployment.
- Verify that your hosting service is correctly configured to serve static files.
General Debugging
- Monitor Console Logs:
Open your browser’s developer console to check for error messages. - Test Incrementally:
Export and test your app in small parts to isolate where issues occur. - Consult Documentation:
Refer to the official Shinylive documentation and community forums for additional help.
Further Reading
- Introduction to Shinylive for R
Get an overview of Shinylive, its components, and its benefits. - Installing and Setting Up Shinylive (R)
Learn how to install the {shinylive} package and configure asset management. - Creating a Basic Shinylive Application (R)
Build and export your first Shinylive app. - Embedding Shinylive Apps in Quarto Documents (R)
Learn how to integrate Shinylive apps directly into your Quarto documents.
Conclusion
Advanced customization and troubleshooting are essential for maintaining robust Shinylive applications. By managing assets carefully, organizing multiple apps effectively, and following best practices, you can ensure your serverless Shiny apps perform reliably on static hosting services. Use the troubleshooting tips to resolve issues quickly and refer to the further reading resources for deeper insights into advanced configurations.
Explore More Articles
Here are more articles from the same category to help you dive deeper into the topic.
Reuse
Citation
@online{kassambara2025,
author = {Kassambara, Alboukadel},
title = {Advanced {Customization} and {Troubleshooting} for
{Shinylive} {(R)}},
date = {2025-03-17},
url = {https://www.datanovia.com/learn/interactive/r/shinylive/advanced.html},
langid = {en}
}