holoviz / panel

Panel: The powerful data exploration & web app framework for Python
https://panel.holoviz.org
BSD 3-Clause "New" or "Revised" License
4.84k stars 520 forks source link

Make objects returned by .bind function .servable #3087

Open MarcSkovMadsen opened 2 years ago

MarcSkovMadsen commented 2 years ago

I'm trying to compare Streamlit to Panel code.

If objects returned by pn.bind where .servable I could remove one line of Panel code and make the communication much simpler.

Panel

import plotly.express as px

def plot(count):
    x = [str(i) for i in range(0, count)]
    y = list(range(0, count))
    return px.bar(x=x, y=y)

import panel as pn

pn.extension("plotly", sizing_mode="stretch_width", template="fast")

count = pn.widgets.IntSlider(name="Count", start=10, end=50, value=10).servable(
    location=True, area="sidebar"
)
icount = pn.bind(plot, count)  # Makes function rerun when the widget value is changed
pn.panel(icount).servable(title="Slider Example", area="main")

Streamlit

import plotly.express as px

def plot(count):
    x = [str(i) for i in range(0,count)]
    y = list(range(0,count))
    return px.bar(x=x, y=y)

import streamlit as st

count = st.sidebar.slider("Count", min_value=10, max_value=50, value=10)
st.plotly_chart(plot(count))
philippjfr commented 2 years ago

+1 from me here. We've considered this in the past and I think the plan around this was to add a simple version of bind to param and then have the Panel based version support this.

MarcSkovMadsen commented 2 years ago

Would be ok to add .servable directly for the time being?

jbednar commented 2 years ago

I do want the Param version of bind and don't know of any reason not to simply implement that, but I'm not sure why that's required for moving forward at the Panel level.