-
-
Notifications
You must be signed in to change notification settings - Fork 111
Supplement .interactive with an Interactive Pipe class #673
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Sounds great! I think this fits well with #533, i.e., expanding the power available from the hvPlot-centric interface. |
You can actually get very close with a hack like ipipeline = (
pd.DataFrame().interactive()
.pipe(extract, country=country_widget)
.pipe(transform, col=col_widget)
) works_almost.mp4But it is not totally satisfactory because
import time
import pandas as pd
import panel as pn
import hvplot.pandas
def extract(_, country):
# In my case this would often be an expense SQL query from a large table
print(country)
time.sleep(1)
value = {"DK": 0, "DE": 3, "US": 6}[country]
return pd.DataFrame(
{
"col1": [value] * 10,
"col2": [value + 1] * 10,
"col3": [value + 2] * 10,
}
)
def transform(series: pd.DataFrame, col):
time.sleep(1)
print(col)
return series[col].sum()
country_widget = pn.widgets.Select(value="DK", options=["DK", "DE", "US"])
col_widget = pn.widgets.Select(value="col1", options=["col1", "col2", "col3"])
ipipeline = (
pd.DataFrame().interactive()
.pipe(extract, country=country_widget)
.pipe(transform, col=col_widget)
)
pn.Column(
ipipeline.widgets(),
ipipeline.panel(loading_indicator=True),
).servable() |
So based on the previous example we can define def interactive(func, *args, **kwargs):
def wrapper(_, *args, **kwargs):
return func(*args, **kwargs)
return (
pd.DataFrame().interactive()
.pipe(wrapper, country=country_widget)
) and get an api like ipipeline = (
interactive(extract, country=country_widget)
.pipe(transform, col=col_widget)
) So the main problem to solve is the missing caching. Full Exampleimport time
import pandas as pd
import panel as pn
import hvplot.pandas
def extract(country):
# In my case this would often be an expense SQL query from a large table
print(country)
time.sleep(1)
value = {"DK": 0, "DE": 3, "US": 6}[country]
return pd.DataFrame(
{
"col1": [value] * 10,
"col2": [value + 1] * 10,
"col3": [value + 2] * 10,
}
)
def transform(series: pd.DataFrame, col):
time.sleep(1)
print(col)
return series[col].sum()
country_widget = pn.widgets.Select(value="DK", options=["DK", "DE", "US"])
col_widget = pn.widgets.Select(value="col1", options=["col1", "col2", "col3"])
def interactive(func, *args, **kwargs):
def wrapper(_, *args, **kwargs):
return func(*args, **kwargs)
return (
pd.DataFrame().interactive()
.pipe(wrapper, *args, **kwargs)
)
ipipeline = (
interactive(extract, country=country_widget)
.pipe(transform, col=col_widget)
)
pn.Column(
ipipeline.widgets(),
ipipeline.panel(loading_indicator=True),
).servable() |
That API does solve an important issue with I'm not sure precisely how we'd define it generally, given that |
Looks like this has been implemented in #720 :) |
Uh oh!
There was an error while loading. Please reload this page.
Background
Hvplot
.interactive
is truly powerful.I believe it has the same potential as Streamlits api. It's simple, intuitive, beautiful and very powerful. And it comes without the downsides of
My Pain
.interactive
only supports pipelines starting from a DataFrame. I would like the same power for any pipeline.As a minimum I would like all the
read_XYZ
likeread_sql
,read_csv
,read_parquet
to be interactive. Most times my pipeline/ data app also holds widgets for which data to extract as it would not be feasible to extract all data for example from a large sql table.But sometimes my data would also be extracted from a larger, costly simulation based on specific arguments. And these arguments should also be presented as widgets.
If possible I would like an api that supports beautiful, readable method chaining and feels like an integrated part of
.interactive
.Reference Example
For example I would like to be able to use the same, intuitive api with built in caching for this pipeline
Existing Apis
I can't see how any of the existing Param/ Panel apis support this. For example not the Pipeline.
This would be a solution though
ipipeline.mp4
But it does not
.interactive
It feels like another api than
.interactive
and thus does not keep things simple.Proposed API
Something like
I would also like the
Interactive
class to recognize Dataframe and just make them.interactive
so that this would also be possibleAdditional Context
memory
cached, cached usingdiskcache
or cached using some method which the user can provide..interactive
data extraction that would be enough to solve this problem pain?extractions
of dataframes and assembles them. That would also be nice to be able to make them.interactive
with caching.The text was updated successfully, but these errors were encountered: