Web Apps with Python - Panel

Web Apps with Python - Panel

(Image by Freepik)

This time, we'll look at the Python library Panel, a highly customisable way to build dashboards and web apps.

I'll also show you how to build and deploy them entirely in the cloud!

(Check out my other posts Web Apps with Python - Dash, Web Apps with Python - Gradio, and Web Apps with Python - Streamlit)

Intro

Panel is an open-source Python package to build dashboards and applications entirely in Python. Panel claims to be flexible enough to build both simple single-page apps and complicated multi-page interactive apps. Panel apps can be coded in both a notebook environment and an IDE.

Availability

Panel is free to install and use. It is already available in Google Colab. In other environments, it can be installed with the command 'pip install panel' in an IDE or '!pip install panel' in a notebook cell.

Example Code

The Panel app gallery offers a range of examples. The official Panel website has a simple step-by-step example to get you started. I do think that Streamlit has a better selection of learning resources, though. Fortunately for Streamlit users, the Panel website explains how to migrate apps from Streamlit to Panel. You can also follow Marc Skov Madsen on Twitter and LinkedIn for helpful tips on using Panel.

Limitations

Sometimes features that are out-of-the-box with other web app libraries such as Gradio, Streamlit, etc, may have to be explicitly added by the developer in a Panel app. See the 'Deployment' section below for details.

Build in the Cloud

GOOGLE COLAB

Google Colab is probably the most convenient place to code Panel apps in the cloud, as you can get started right away with import panel as pn.

In my blog post Web Apps with Python - Gradio, I built an app to analyse the polarity and subjectivity of text input using the Textblob library. I recreated the same app in Panel -- here is my public Colab notebook with the code. Notice that you have to add pn.extension() in the cell to view the app in the cell output.

Deployment

Panel apps can be deployed for free on Hugging Face Spaces. Check out the guide: https://panel.holoviz.org/how_to/deployment/huggingface.html

I followed these steps and got my Panel app running here. Feel free to play with it!

Contrast how my Panel app looks compared to the Gradio app I built in my blog post Web Apps with Python - Gradio.

My Gradio app has a 'Submit' and 'Clear' button for the text input box. These come for free with the Textbox input widget in Gradio. The corresponding TextInput widget in Panel does not have these features, so you'd have to design them yourself using the Button widget in Panel.

Conclusion

Panel is a great way to build dashboards and apps in Python, and offers a wide range of options for customisation. Panel apps can be coded in both IDEs and notebook environments, making it easy to integrate into your data science workflow.

Panel is not as well-known as other frameworks such as Dash and Streamlit and has fewer learning resources at present. But the project is under active development, so you can be confident that it will continue to improve.