Panel Documentation

repository·main·Indexed 26 days ago

https://github.com/holoviz/panel

An open-source Python library for building data exploration tools, dashboards, and complex web applications. Panel integrates with the PyData ecosystem and supports multiple deployment modes, including web servers (Tornado, Flask, Django, FastAPI), client-side WASM (Pyodide, PyScript), Jupyter notebooks, and static exports. It provides reactive and callback APIs, supports Narwhals for DataFrame interoperability, and is transitioning to a modern Material UI-based API.

Tokens
186.4K
Snippets
422
Records
904
Agent score
91%

What's inside Panel

  1. Overview of running Panel in the browser with WASM

    main

    Panel can be run directly in the web browser using WebAssembly (WASM) via technologies like Pyodide or PyScript. This approach allows you to execute Python code and render Panel applications entirely on the client side, eliminating the need for a separate Python/Bokeh server process.

    Key capabilities include:

    • Running Python libraries and manipulating the DOM from Python in the browser.
    • Converting existing Panel applications into WASM-based applications.
    • Manually installing Panel in the browser to render components.
    • Embedding live Panel components in Sphinx documentation.
    • Using JupyterLite to render interactive Panel output.
  2. Overview of Panel

    main

    Panel is an open-source Python library for developing robust tools, dashboards, and complex web applications entirely within Python. It integrates with the PyData ecosystem and supports both high-level reactive APIs and lower-level callback-based APIs.

    Key capabilities include:

    • Developing in editors or Jupyter notebooks.
    • Combining PyData tools and plotting libraries.
    • Adding bi-directional communication to data apps.
    • Creating interactive big data applications with cross-filtering.
    • Building high-performing, streaming, or browser-only applications.
    • Creating production-ready web applications.
  3. Explore Panel styling and design options

    main

    Panel offers several ways to customize the appearance of your applications and components. You can:

    • Apply a Design: Switch between different design systems.
    • Toggle themes: Switch between themes like 'light' and 'dark'.
    • Apply CSS: Use custom CSS for specific styling needs.
    • Customize a Design: Use CSS variables to modify existing designs and themes.
    • Customize Loading Icon: Change the appearance of the loading indicator.
    • Control Visibility: Manage when components are visible in the UI.
    • Style Plotting Libraries: Apply specific styling to integrated libraries including Altair, ECharts, Matplotlib, Plotly, and Vega Lite.
  4. Enable Profiling and Debugging in Panel

    main

    Panel provides an admin dashboard to help diagnose performance bottlenecks and track application issues. This dashboard allows you to:

    • Monitor resource usage and user behavior via the Admin Panel.
    • Profile application performance using tools like snakeviz or memray to identify bottlenecks.
    • View application logs directly within the admin dashboard for better visibility than standard server logs.
  5. Compare Panel and ipywidgets for application development

    main

    When choosing between Panel and ipywidgets (Jupyter Widgets), consider the following architectural differences:

    • Deployment & Origin: Panel is based on Bokeh and was designed for standalone deployments from the start. ipywidgets originated in the Jupyter ecosystem and, while now supporting standalone deployment (e.g., via Voila), its history is rooted in the notebook environment.
    • Styling: Since Bokeh 3.0 and Panel 1.0, both Panel and ipywidgets support similar levels of HTML/CSS styling customization.
    • Static HTML Export: Panel widgets support easy embedding into static HTML pages (useful for Sphinx documentation or HTML reports). ipywidgets requires a complex "embed widget state" operation to copy state from Python to the web page.
    • Logic Separation (Param): Panel leverages the Param library to separate scientific/business logic from the GUI. By declaring parameters (name, type, range, etc.) using Param, you can use the same code for command-line tools, batch jobs, or automatic Panel widget generation without rewriting the core logic.
    • Reactivity: Panel widgets are reactive, allowing you to declare dependencies between code and widget parameters. This enables a declarative programming style where users can pass widget objects directly to Python functions, avoiding the need to write explicit Python callbacks.
    • Interoperability: The two ecosystems are interoperable. You can use Panel/Bokeh widgets in an ipywidgets app via jupyter_bokeh, or use ipywidgets in a Panel/Bokeh app via ipywidgets_bokeh.
  6. Understand Panel component types

    main

    Panel applications are built using three primary component types:

    • Pane: Wraps a user-supplied object (of almost any type) into a renderable view. It automatically updates the view when the wrapped object or its parameters change.
    • Widget: A control component used for user input (e.g., clicking or editing in a browser). Widgets can be controlled via the browser or from within Python.
    • Panel: A hierarchical container used to layout multiple components (panes, widgets, or other Panels) into an organized app or dashboard.
  7. Choose the appropriate Panel API for your project

    main

    Panel provides three primary API approaches depending on your project's complexity and requirements:

    1. Reactive API: Use pn.bind or the pn.depends decorator to link functions directly to widgets. This is the recommended approach for most users and projects as it is efficient, explicit, and maintainable.
    2. Declarative API: Use Parameterized classes to declare parameters and their ranges. This is ideal for writing libraries or core code that needs to support an optional GUI interface, as it provides automatic GUI generation and value checking.
    3. Callbacks API: Manually declare callbacks to update panels or panes. Use this when you need low-level, arbitrary event handling or want to implement custom logic alongside other API approaches.
  8. Explore the Panel module structure

    main

    Panel is organized into several specialized subpackages and modules. Key modules include:

    • panel.auth: Authentication handlers.
    • panel.chat: Chat components.
    • panel.command: CLI commands.
    • panel.compiler: Utilities for bundling/compiling JS and CSS.
    • panel.config: Configuration and extension objects.
    • panel.custom: Baseclasses for custom components.
    • panel.depends: Exposes param.bind and param.depends.
    • panel.interact: The interact API implementation.
    • panel.io: IO-related functionality.
    • panel.layout: Layout components.
    • panel.links: Javascript linking and callbacks.
    • panel.models: Bokeh model implementations.
    • panel.pane: Pane components.
    • panel.param: Integration with the param library.
    • panel.pipeline: The Pipeline component.
    • panel.reactive: Reactive API baseclasses.
    • panel.template: Template components.
    • panel.theme: Design and Theme components.
    • panel.util: Generic utilities.
    • panel.viewable: Baseclasses for all Panel components.
    • panel.widgets: Widget components.
  9. Compare Panel and Dash for dashboard development

    main

    When choosing between Panel and Dash for Python-based dashboarding, consider these key architectural differences:

    • Notebook Integration: Panel provides seamless support for Jupyter notebooks, allowing you to add controls and layouts directly into a workflow. Dash is primarily focused on standalone dashboards.
    • Syntax and Customization: Panel uses a concise, expressive Pythonic syntax. Dash exposes more underlying HTML and CSS, which offers high customization but requires more web development knowledge.
    • Plotting Library Support: Panel is plotting-library agnostic and supports a wide range of libraries (including Plotly) out of the box. Dash has native support for Plotly but requires separate extension packages for other libraries.
    • State Management:
      • Dash stores per-user session state in the client (browser), which can be highly scalable for many simultaneous sessions.
      • Panel allows per-user, per-session state on both the server and the client. This enables server-side caching of intermediate computations, making complex pipelines (like those using Datashader) much more responsive by reusing aggregated data instead of recomputing every stage on every interaction.
  10. Panel deployment options

    main

    Panel supports several deployment modes:

    • Web Server: Run as a web application using Tornado (default), Flask, Django, or FastAPI.
    • Client-side (WASM): Deploy as a standalone client-side application using Pyodide or PyScript via the panel convert command.
    • Notebook: Use as an interactive component within a Jupyter notebook.
    • Static: Export as a static .html page, .gif video, or .png image.
  11. Understand Panel communication channels and requirements

    main

    Panel facilitates communication between Python code and JavaScript/HTML objects in a web browser. The level of interactivity available depends on the communication type supported by your environment:

    1. One-time Python->JS: Basic one-way communication (e.g., exporting to a static .html file). No Python process remains running.
    2. Ongoing Python->JS synchronization: Python sends updates to JS when Python attribute values change. Required for dynamic updates in notebooks.
    3. Ongoing JS->Python synchronization: JS sends updates back to Python when users interact with widgets.

    Full bidirectional (JS<->Python) synchronization requires all three types and is typically achieved using a standalone server (via panel serve) or specific integration libraries.