Skip to content

Enable combining pn.serve a function with .servable #3680

@MarcSkovMadsen

Description

@MarcSkovMadsen

Background

I'm trying to contribute a PanelFrontend to lightning.ai in Lightning-AI/pytorch-lightning#13531.

The feedback is that they would like an api where the PanelFrontend is instantiated with a render_fn function that runs the Panel code. The main argument is that this is consistent with the StreamlitFrontend.

Personally I think this is problematic because 1) Most panel users are familiar with panel serve of a script or notebook. pn.serve of a function works a bit differently because 2) You can't use .servable with pn.serve and a function. But my impression is that starting with an api similar to what they already have is easier for them to understand and approve.

Example

import panel as pn

def view_1():
    text_input = pn.widgets.TextInput(name="Input", value="abcd")

    return pn.Column(
        "# Input",
        text_input,
    )

def view_2():
    pn.panel("# Input").servable()
    pn.widgets.TextInput(name="Input", value="abcd").servable()
    return pn.Column() # Hack: Without it the server will never show

pn.serve(
    {"view1": view_1, "view2": view_2}
)

Request

My request is to support the combination of pn.serve of a function using .servable as defined in view_2.

Extra Motivation

The .servable api is simpler and similar to the Streamlit api. Its easier to work with for a lot of users.

Discussion

I think it would be possible to wrap the view_x functions in some other function that returns the result of view_1 because it is not none and does something (what) to collect the .servable marked items of view_2 and return them in a template. BUT HOW?

Metadata

Metadata

Assignees

No one assigned

    Labels

    TRIAGEDefault label for untriaged issues

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions