Shiny for Python

A comparison with other frameworks and advantages

What's Shiny (for Python)?

Shiny was developed in 2012 as an R package and enables data scientists to create interactive web applications and dashboards directly in R. Users can explore, visualize, and analyze data without needing to program themselves. This makes data analysis accessible to a broader group of decision-makers and promotes data-driven decision-making.

In 2022, Posit expanded the Shiny ecosystem with Shiny for Python, allowing applications to also be developed in Python. While the R Shiny community has historically been more academically oriented, the rapidly growing Python community is more focused on business requirements. At eoda, we use Shiny for Python for interactive web applications with complex analyses that support companies in making data-driven decisions.

R Shiny and Shiny for Python follow the same principles in terms of architecture, reactive programming logic, deployment, and scaling. This enables Python developers to create interactive dashboards and web applications directly in Python. The integration of libraries such as NumPy, Polars, PyTorch, or TensorFlow, as well as integration into modern development and CI/CD processes, makes Shiny for Python particularly suitable for production-ready data products and ML-supported applications.

What is Shiny (for Python) suitable for?

For more than 15 years, we have been developing data-driven solutions and dashboards for a wide range of industries. Based on our experience, Shiny is a tool that is best suited for:

  • Companies / organizations that not only want to visualize data, but also want to make and execute decisions based on it
  • Having different users who need access to this information in their daily work.
  • Want to share understandable representations of information with others

Shiny for Python makes particular sense for teams that

  • already use established Python-based pipelines for development, testing, and deployment,
  • want to create, use, and share fast visualizations and interactive web applications,
  • want to continue using the extensive Python ecosystem of libraries and tools for machine learning, data analysis, and visualization.

Comparison of Shiny for Python

Shiny for Python vs Streamlit

Streamlit is an open-source framework for Python that allows interactive web applications for data analysis and machine learning to be created quickly. Streamlit follows a very simple and declarative approach. An application is essentially written like a normal Python script that is completely re-executed with every user interaction. This makes it particularly easy to get started and is mainly aimed at data scientists who want to build prototypes or simple data apps without extensive web development knowledge.

Shiny for Python, however, uses reactive logic in which an input triggers a direct recalculation/change only in the corresponding components that the input refers to. Like R Shiny, Shiny for Python separates the user interface and server, which facilitates maintenance and scalability even for complex applications. For this reason, we choose Shiny (for Python) for applications that will evolve over time.

Shiny for Python Streamlit
ReactivityAutomaticThe entire script is re-executed upon interaction
Learning curveSomewhat more structured, conceptually strongerVery low barrier to entry
Use CasesStructured business or analytics appsRapid prototypes, data demos, ML showcases
ScalabilityHighly scalable through modular architecture and reactive modelLimited scalability for very large or complex applications
Target audienceData scientists with a need for scalable architectureData scientists who want to show results quickly

Shiny for Python vs Dash

Shiny for Python and Dash differ in their programming logic: Dash uses an explicit callback system in which it must be precisely defined which inputs influence which outputs. This provides maximum control over the data flow, but requires more manual structuring.

Here as well, Shiny for Python relies on reactive programming: dependencies between inputs and outputs are automatically detected, so that only the affected parts of the application update themselves. This results in less boilerplate code, and complex, highly interconnected interfaces can be implemented comparatively elegantly.

While Shiny is particularly well suited for dynamic, data-driven applications with many reactive elements, Dash stands out through its clear architecture and its close integration with visualizations.

Shiny for Python Dash
ReactivityAutomaticExplicit callbacks
Learning curveIntuitiverClearly structured
Use CasesComplex analytics and business apps with
many interactive dependencies
Interactive dashboards, data-driven web apps
ScalabilityWell suited for growing, modular appsHighly scalable with a clean architecture design
Target audienceData scientists with a need for scalable architectureDevelopers and data scientists who want full control over the data flow

Shiny for Python and Jupyter Notebooks

Shiny for Python can be used directly in Jupyter Notebook or JupyterLab, combining interactive web app functionality with the classic data science workflow. While Jupyter is primarily designed for exploratory, linear analysis, Shiny complements this approach with true reactivity: UI elements automatically respond to changes and update only the affected parts of the application. This makes Shiny in Jupyter particularly suitable for interactive data analyses, teaching purposes, and rapid prototypes. For production-grade, scalable multi-user applications, however, Shiny is usually run as a standalone web app outside of the notebook.

Shiny for Python (in Jupyter) Classic Jupyter Notebook
ReaktivitätAutomatischKeine echte Reaktivität, manuelles erneutes Ausführen von Zellen
LernkurveEtwas höher durch reaktives KonzeptSehr niedrig, da lineares Skriptprinzip
AnwendungsfälleKomplexe WebanwendungenExplorative Analyse, Experimente, Dokumentation
SkalierbarkeitBegrenzt im Notebook, besser als eigenständige AppNicht für skalierbare Web-Anwendungen gedacht
ZielgruppeData Scientists mit Bedarf an interaktiven Analyse-InterfacesData Scientists, Forschende, Studierende für explorative Arbeit

Shiny Express

Shiny Express ist eine vereinfachte Form von Shiny for Python, die auf eine möglichst schnelle und unkomplizierte Entwicklung interaktiver Anwendungen abzielt. Anstelle einer strikten Trennung von Oberfläche und Serverlogik nutzt es eine kompakte, skriptähnliche Herangehensweise. Dadurch entsteht weniger struktureller Aufwand und Anwendungen lassen sich mit überschaubarem Code realisieren. Besonders für kleinere Vorhaben, Demonstrationen oder den Einsatz in Lehrkontexten ist dieser Ansatz gut geeignet. Für umfangreichere Projekte bietet die klassische Shiny-Variante jedoch mehr organisatorische Klarheit und langfristige Erweiterungsmöglichkeiten.

Shiny for Python Shiny Express
ReaktivitätAutomatischKeine echte Reaktivität, manuelles erneutes Ausführen von Zellen
LernkurveMittel bis höher – Reaktivitätskonzept und App-Struktur müssen verstanden werdenNiedrig – schneller Einstieg durch reduzierte Komplexität
AnwendungsfälleProduktive Analyse-Tools, Business-Apps, komplexe DashboardsPrototypen, Lehrbeispiele, schnelle Daten-Demos
SkalierbarkeitGut für langfristige, skalierbare AnwendungenBegrenzt bei stark wachsenden Anwendungen
ZielgruppeData Scientists und EntwicklerInnen mit Struktur- und SkalierungsbedarfEinsteigerInnen, Lehrende, schnelle Projektumsetzungen

Shiny for Python Serverless (Shinylive)

Mit Hilfe von Shinylive und WebAssembly (Wasm) lassen sich Shiny-Apps ganz einfach in einem Browser nutzen – ohne die Notwendigkeit eines Python-Servers. Dabei wird der Python-Code direkt im Browser ausgeführt, sodass keine serverseitige Infrastruktur erforderlich ist. Jedoch muss hier ein Kompromiss geschlossen werden: Wegen der kaum möglichen Datenbereitstellungen, sind die Möglichkeiten komplexer Apps hier deutlich eingeschränkten gegenüber der klassischen Sever-Client-Architektur einer Shiny-App. Das Ergebnis ist eine statische Website, die dennoch interaktive Shiny-Funktionalität bietet. Dadurch werden Deployment, Skalierung und Wartung deutlich vereinfacht. Shinylive eignet sich besonders für öffentliche Dashboards, Dokumentationen, Lernmaterialien oder Anwendungen mit vielen gleichzeitigen Nutzenden, bei denen keine serverseitige Logik wie Datenbankzugriffe notwendig ist.

Testing mit Playwright in Shiny for Python

Playwright ist ein modernes Testwerkzeug zur automatisierten Überprüfung von Webanwendungen. Für Shiny for Python-Apps kann Playwright verwendet werden, um die Funktionalität und Interaktionen einer App automatisiert zu testen.

Dabei simuliert Playwright reale Nutzeraktionen, z.B. das Klicken auf Buttons, das Ausfüllen von Eingabefeldern oder das Navigieren durch die Oberfläche. So lässt sich überprüfen, ob die Anwendung wie erwartet reagiert und ob Änderungen im Code unbeabsichtigte Fehler verursachen.

Automatisierte Tests mit Playwright tragen somit zur Qualitätssicherung bei und unterstützen eine stabile Weiterentwicklung von Shiny-Anwendungen.

Beispiel eines Playwright-Test:

from services.data import filter_species

def test_filter_species():
    df = ...
    out = filter_species(df, "setosa")
    assert (out["Species"] == "setosa").all()

Tipps & Hinweise

Nutzen Sie anfangs Starter-Templates / Boilerplates um sich den Einstieg zu erleichtern z. B.

  • Inline Dokumentation helfen bei der Nachvollziehbarkeit
  • Schrittweise Vorgehen und bei jeder Iteration Feedback von Usern einholen
  • Nutzen Sie zur Versionskontrolle verschiedene Tools wie Git
  • Testing, Testing, Testing: Schreiben Sie Unit-Tests und End-to-End-Tests. Shiny for Python bietet hier ein eigenes Framework

 

 

Fazit

Mit Shiny for Python eröffnen sich für Python-EntwicklerInnen neue Möglichkeiten der Visualisierung und Interaktion mit Daten. Durch sein reaktives Programmiermodell, die klare Trennung von UI und Serverlogik sowie die gute Integration in bestehende Python-Ökosysteme eignet es sich besonders für datengetriebene Business-Anwendungen und produktionsnahe Analyse-Tools. Mit einer klaren Projektstruktur, sauber getrennten Services, konsequentem Testing und iterativer Entwicklung lassen sich Shiny-Apps nachhaltig, wartbar und teamfähig umsetzen.

Sie haben das Potenzial von Shiny for Python erkannt und möchte dieses Live erleben?

Seit über 15 Jahren sind wir der führende Anbieter für R-basierte Projekte und Shiny-App-Entwicklung – sprechen Sie uns an und gemeinsam gehen wir die nächsten Schritte.

Veröffentlicht: 19. July 2023

AutorIn

Christian Schreiner

Christian Schreiner is a marketing specialist at eoda GmbH. His responsibilities include data infrastructures and marketing solutions. In his spare time, he is interested in search engine optimization and trends in online communication.

Row edge-slant Shape Decorative svg added to top
Row edge-slant Shape Decorative svg added to bottom

Starten Sie jetzt durch:
Wir freuen uns auf den Austausch mit Ihnen. 







    Scroll to Top