Photo by Eugene Zhyvchik on Unsplash

Deploying ShinyPy

Berk Orbay
berk-orbay
Published in
4 min readNov 14, 2023

--

I love Shiny in R. I coded a considerable amount of Shiny projects. I had production level Shiny apps. I love Golem and Golemverse. I teach R. I teach Shiny. I can never be thankful enough to people who are making these libraries.

Nowadays, I code in Python much more than I code in R. Until recently, I have never had tried ShinyPy. I have almost always used Streamlit in Shiny’s absence to prototype. I briefly tried Pynecone (Reflex), Anvil, Gradio, Flet and a few others. Nothing came close to Streamlit’s convenience.

ShinyPy is actually named “Shiny for Python” by Posit. The problem with the Shiny’s nomenclature is it is a known word/adjective. Half the time I was very frustrated with my Google searches. Googling “doing this in Shiny Python” is even more frustrating. Thus, I am calling it ShinyPy.

I had a few previous attempts to test ShinyPy but I never had a significant project to code in ShinyPy. I spent last couple of days to find my way around ShinyPy and deploy a project to cloud. Here are my impressions.

First Impression

I am impressed. Core functionality of Shiny is successfully transported to Python. It uses what FastAPI uses under the hood. There are nice themes thanks to shinyswatch package. It seems to have found a way to integrate more services (e.g., plotly) with widgets etc.

Second impression… I am constantly frustrated. It is expected in such a young (~1 year old) framework. Shinyverse is Python not as nearly mature as in R and it does not seem to take off. Even a basic dashboard (such as in shinydashboard) is hard to come by. Frontend management is more disorganized (not my strongest suit). Interoperability is questionable (for now, for me).

My Projects

I coded two simple projects: Producers Atlas and German Vocabulary.

First one is slightly more complex. Producers Atlas includes data of electricity power plants in Turkey. It contains, some data frame manipulation, plotting and showing lots of data.

Deploy: GCP Cloud Run

I tried to deploy it to a cloud service. Personally, I dislike Shiny Server (I love Shinyapps though). It is (was) usually messy to deal with. It also represents the conflict of open source vs making money. Posit clips some critical infrastructure, such as authentication, from Shiny Server Open and directs you to its commercial solution.

At ShinyPy deployment page, under hosting options they say that it is possible to deploy it to cloud without Shiny Server. Though, you need “sticky sessions” (or session affinity).

I had experience with a few low-hassle and “cost-effective” (depending on usage cloud services. One of them is GCP Cloud Run, the other alternative was AWS App Runner. The latter does not use “sticky sessions” therefore it is eliminated. (ps. I ran into serious cost issues in ECS. Therefore I did not dare to go that way.)

I think I figured out deployment and put together a Gist to explain how. Once you reach to a result, you understand that it is quite straightforward.

Some alternative deployment services might be Replit and AWS Elastic Beanstalk.

Deploy: Github Pages (Shinylive)

The second product is so simple. It is just a basic flashcard application for German words. The appeal is I can deploy it as a static page to GitHub pages instead of a server or shinyapps, thanks to Shinylive. Shinylive is the new method of using Pyodide with Shiny (something similar is going on with Streamlit as well)

I had a semi-success. Single file app (e.g., app.py) is successful. But I failed to deploy multi-file (either an external data file or a custom python module) projects. You are free to check the repository.

My simple standalone Shinylive app (built under 30 mins)

Final Thoughts and Recommendations

ShinyPy is on its way to be a viable and reliable full stack option for Python, fast. In my opinion, a major hurdle is convenience (from the top of my head, some of which are session state, authorization, dashboarding, and some awesome dataframe library like Glide Data Grid). It brings a ton of good stuff, but some essentials are still missing.

My top recommendation is to steal from Streamlit’s playbook. Currently, I am so close to replace Streamlit with Shiny. Thanks to all the people who make Shiny in Python a reality.

--

--

Berk Orbay
berk-orbay

Current main interests are #OR and #RL. You may reach me at Linkedin.