Skip to content
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

Allow callables to be used as options for NestedSelect #5969

Merged
merged 7 commits into from
Dec 2, 2023

Conversation

ahuang11
Copy link
Contributor

@ahuang11 ahuang11 commented Dec 2, 2023

As mentioned here: #5791 (comment)

@pn.cache
def list_options(level, value):
    value_path = "/".join(list(value.values()))
    url = f"https://downloads.psl.noaa.gov/Datasets/ncep.reanalysis/{value_path}"

    options = [var.rstrip("/") for var in pd.read_html(url)[0]["Name"].dropna()[1:]]
    if level == "time_step":
        options = {option: list_options for option in options if option[0].isupper()}
    elif level == "level_type":
        options = {option: list_options for option in options if option[0].islower()}
    else:
        options = [option for option in options if option.endswith(".nc")]

    return options


select = pn.widgets.NestedSelect(
    options=list_options,
    levels=["time_step", "level_type", "file"],
)
select
Screen.Recording.2023-12-01.at.4.26.21.PM.mov

Copy link

codecov bot commented Dec 2, 2023

Codecov Report

Attention: 4 lines in your changes are missing coverage. Please review.

Comparison is base (cdb9e70) 84.35% compared to head (7a2118f) 84.36%.

Files Patch % Lines
panel/widgets/select.py 94.73% 3 Missing ⚠️
panel/tests/widgets/test_select.py 97.67% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5969   +/-   ##
=======================================
  Coverage   84.35%   84.36%           
=======================================
  Files         291      291           
  Lines       43368    43452   +84     
=======================================
+ Hits        36584    36659   +75     
- Misses       6784     6793    +9     
Flag Coverage Δ
ui-tests 40.80% <8.00%> (-0.09%) ⬇️
unitexamples-tests 72.47% <96.00%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@philippjfr philippjfr merged commit 6690bd3 into main Dec 2, 2023
12 of 13 checks passed
@philippjfr philippjfr deleted the select_options_callable branch December 2, 2023 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants