Introduction
As you gain experience with Shinylive for Python, you may want to customize your applications further and ensure they run reliably in production. This tutorial covers advanced topics such as managing web assets, handling multiple Shiny apps within one deployment, and troubleshooting common issues encountered when running Shinylive apps.
1. Asset Management
Efficient asset management is crucial for smooth performance. The shinylive Python package downloads and caches the necessary web assets (HTML, JavaScript, CSS, and WASM) for your app.
Checking Asset Information
Run the following command in your terminal to view asset details:
shinylive extension info
This displays the version of the shinylive package, the asset version, and the cache directory.
Updating and Cleaning Assets
Download/Update Assets:
If you need the latest web assets, update them with:shinylive extension language-resources
Clean Up Old Assets:
To free up space and avoid version conflicts, clean up outdated assets:shinylive extension clean
Regularly check and update your assets to maintain compatibility with your app.
2. Handling Multiple Applications
When managing more than one Shiny app, you can export each into separate subdirectories to share common web assets. This approach streamlines maintenance and deployment.
Example: Exporting Multiple Apps
Assume you have two Python Shiny apps in directories myapp1
and myapp2
. Export them using:
shinylive export myapp1 site --subdir app1
shinylive export myapp2 site --subdir app2
This command creates a site/
folder with subdirectories app1
and app2
, each containing its respective static files while sharing common assets.
3. Troubleshooting Common Issues
Even with careful setup, issues may arise. Here are some common troubleshooting steps:
Asset Issues
- Symptom: The app fails to load or reports missing assets.
- Solution:
- Verify asset versions using
shinylive extension info
. - Update assets if necessary using the update commands.
- Ensure your network or file permissions allow asset downloads.
- Verify asset versions using
Export Errors
- Symptom: The export process fails or produces incomplete output.
- Solution:
- Confirm your Shiny for Python app runs correctly in your development environment.
- Double-check file paths and directory permissions.
- Run a clean export by removing previous output directories before exporting again.
Deployment Problems
- Symptom: The app works locally but not when deployed to static hosting (e.g., GitHub Pages).
- Solution:
- Ensure that your hosting service is correctly configured to serve static files from your
site/
directory. - Verify that asset paths remain relative after deployment.
- Test the deployed site using a local static server (e.g.,
python3 -m http.server --directory site --bind localhost 8008
).
- Ensure that your hosting service is correctly configured to serve static files from your
Further Reading
- Introduction to Shinylive for Python
An overview of Shinylive for Python and its benefits. - Installing and Setting Up Shinylive for Python
Learn how to install the shinylive Python package and configure asset management. - Creating a Basic Shinylive Python Application
Step-by-step instructions for building and exporting your first Shinylive Python app. - Embedding Shinylive Python Apps in Quarto Documents
Discover how to embed your Shinylive apps directly into Quarto documents.
Conclusion
Advanced customization and troubleshooting are essential to ensure your Shinylive Python applications perform reliably in a serverless environment. By managing assets effectively, organizing multiple applications properly, and following best practices, you can optimize your interactive Shiny apps for smooth operation on static hosting platforms.
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} {(Python)}},
date = {2025-03-20},
url = {https://www.datanovia.com/learn/interactive/python/shinylive/advanced.html},
langid = {en}
}