holoviz-topics / examples

Visualization-focused examples of using HoloViz for specific topics
https://examples.holoviz.org
Creative Commons Attribution 4.0 International
80 stars 24 forks source link

Modernize portfolio optimizer #376

Closed jtao1 closed 2 weeks ago

jtao1 commented 3 months ago

Modernizing an example checklist

Preliminary checks

Change ‘anaconda-project.yml’ to use the latest workable version of packages

Plot API updates (discussed on a per-example basis)

Interactivity API updates (discussed on a per-example basis)

Panel App updates (discussed on a per-example basis)

General code quality updates

Text content

Visual appearance - Example

Visual appearance - Gallery

Workflow (after you have made the changes above)

github-actions[bot] commented 3 months ago

Your changes were successfully integrated in the dev site, make sure to review the pages of the projects you touched before merging this PR: https://holoviz-dev.github.io/examples/. You can also download an archive of the site from the workflow summary page which comes in handy when your dev site built was overriden by another PR (we have a single dev site!).

maximlt commented 2 months ago

I have a suggestion about the notebook being a little dry and lacking context. Maybe you could throw the notebook content at ChatGPT and ask for it to add some brief explanations about the underlying analysis. That's just a suggestion, so feel free to ignore it if you don't feel like it. I think though that ChatGPT could do a good job at this, given this is I believe a very common kind of analysis.

github-actions[bot] commented 2 months ago

Your changes were successfully integrated in the dev site, make sure to review the pages of the projects you touched before merging this PR: https://holoviz-dev.github.io/examples/. You can also download an archive of the site from the workflow summary page which comes in handy when your dev site built was overriden by another PR (we have a single dev site!).

jbednar commented 2 months ago

It's possible we'll try to migrate to pn.rx

Is there anyone who is arguing for keeping it hvplot.interactive? pn.rx seems like the obvious thing to do, unless someone is very convincingly arguing otherwise.

ahuang11 commented 1 month ago

Was helping Jason with rx and it felt like rx was a bit magical / unintuitive to me.

Also, we weren't sure how to separate out the widgets to better lay out the dashboard, unlike pn.Param.

I'm -1 on using rx since I think it could just potentially confuse new users with all the ways to do something--at least until there are more examples and docs on how to use it, i.e. do this/not that, good patterns/anti-patterns.

from io import BytesIO
import pandas as pd
import panel as pn
pn.extension()

@pn.cache
def get_stocks(data):
    if data is None:
        stock_file = 'https://datasets.holoviz.org/stocks/v1/stocks.csv'
    else:
        stock_file = BytesIO(data)
    return pd.read_csv(stock_file, index_col='Date', parse_dates=True)

file_input = pn.widgets.FileInput(sizing_mode='stretch_width')

stocks = pn.rx(get_stocks)(file_input)

selector = pn.widgets.MultiSelect(
    name='Select stocks', sizing_mode='stretch_width',
    options=stocks.columns.to_list()
)

selected_stocks = stocks.rx.pipe(
    lambda df, cols: df[cols] if cols else df, selector
)

pn.Column(selected_stocks)
image

Lastly, upon printing rx objects, it raises an error https://github.com/holoviz/param/issues/939

ahuang11 commented 1 month ago

Ok I just realized there's a section in Panel about rx; I was too focused on the param docs.

To split the widget + column, you need to wrap it in the corresponding pane; personally I'd prefer a method to call to do so, e.g. selected_stocks.get_pane()

from io import BytesIO
import pandas as pd
import panel as pn
pn.extension()

@pn.cache
def get_stocks(data):
    if data is None:
        stock_file = 'https://datasets.holoviz.org/stocks/v1/stocks.csv'
    else:
        stock_file = BytesIO(data)
    return pd.read_csv(stock_file, index_col='Date', parse_dates=True)

file_input = pn.widgets.FileInput(sizing_mode='stretch_width')

stocks = pn.rx(get_stocks)(file_input)

selector = pn.widgets.MultiSelect(
    name='Select stocks', sizing_mode='stretch_width',
    options=stocks.columns.to_list()
)

selected_stocks = stocks.rx.pipe(
    lambda df, cols: df[cols] if cols else df, selector
)

pn.Column(
    pn.Row(file_input, selector),
    pn.pane.DataFrame(selected_stocks),
)
github-actions[bot] commented 1 month ago

Your changes were successfully integrated in the dev site, make sure to review the pages of the projects you touched before merging this PR: https://holoviz-dev.github.io/examples/. You can also download an archive of the site from the workflow summary page which comes in handy when your dev site built was overriden by another PR (we have a single dev site!).

github-actions[bot] commented 1 month ago

Your changes were successfully integrated in the dev site, make sure to review the pages of the projects you touched before merging this PR: https://holoviz-dev.github.io/examples/. You can also download an archive of the site from the workflow summary page which comes in handy when your dev site built was overriden by another PR (we have a single dev site!).

jbednar commented 1 month ago

@ahuang11 : Ok I just realized there's a section in Panel about rx; I was too focused on the param docs.

Can you please make a PR on Param putting in an explicit link to the Panel rx docs wherever you would have found them? Right now it only links to the main Panel site, but pointing directly to Panel rx info would presumably prevent others from having the same experience you did.

github-actions[bot] commented 1 month ago

Your changes were successfully integrated in the dev site, make sure to review the pages of the projects you touched before merging this PR: https://holoviz-dev.github.io/examples/. You can also download an archive of the site from the workflow summary page which comes in handy when your dev site built was overriden by another PR (we have a single dev site!).

github-actions[bot] commented 1 month ago

Your changes were successfully integrated in the dev site, make sure to review the pages of the projects you touched before merging this PR: https://holoviz-dev.github.io/examples/. You can also download an archive of the site from the workflow summary page which comes in handy when your dev site built was overriden by another PR (we have a single dev site!).

github-actions[bot] commented 2 weeks ago

Your changes were successfully integrated in the dev site, make sure to review the pages of the projects you touched before merging this PR: https://holoviz-dev.github.io/examples/. You can also download an archive of the site from the workflow summary page which comes in handy when your dev site built was overriden by another PR (we have a single dev site!).

droumis commented 2 weeks ago

I made a lot of changes. There were still many issues: headings, grammatical, organizational, textual. In the future, the PRs need to be further along prior to asking for a final review.

github-actions[bot] commented 2 weeks ago

Your changes were successfully integrated in the dev site, make sure to review the pages of the projects you touched before merging this PR: https://holoviz-dev.github.io/examples/. You can also download an archive of the site from the workflow summary page which comes in handy when your dev site built was overriden by another PR (we have a single dev site!).