-
Notifications
You must be signed in to change notification settings - Fork 0
Select component: add prop multiple
#102
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
2ffa9be
add multiple to select component
clarasb e1677bf
update changes.md and formatting
clarasb 493d660
Merge branch 'main' into clarasb-101_select_component_add_multiple
clarasb da67e20
update
clarasb f8c9f6e
add demo panel E
clarasb fc343b0
add demo panel E
clarasb 7244c03
update demo panel E
clarasb 2281406
update Changes
clarasb 1a8215b
update Changes
clarasb d5bc83f
update Changes
clarasb b71b36a
update Changes
clarasb 0cd39a4
Update chartlets.py/chartlets/components/select.py
clarasb 7d74f67
update formatting
clarasb d5c98d5
add test for select.tsx regarding `multiple` property
clarasb ec5c855
update test for Select.tsx
clarasb 8dd4c4a
Merge branch 'refs/heads/main' into clarasb-101_select_component_add_…
clarasb f60370e
resolved conflicts and new panel G
clarasb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| import altair as alt | ||
| import pandas as pd | ||
| from chartlets import Component, Input, State, Output | ||
| from chartlets.components import VegaChart, Box, Select, Typography | ||
|
|
||
| from server.context import Context | ||
| from server.panel import Panel | ||
|
|
||
|
|
||
| panel = Panel(__name__, title="Panel G") | ||
|
|
||
|
|
||
| @panel.layout(State("@app", "selectedDatasetId")) | ||
| def render_panel( | ||
| ctx: Context, | ||
| selected_dataset_id: str = "", | ||
| ) -> Component: | ||
| dataset = ctx.datasets.get(selected_dataset_id) | ||
| variable_names, selected_var_names = get_variable_names(dataset) | ||
|
|
||
| select = Select( | ||
| id="selected_variable_name", | ||
| value=[], | ||
| label="Variable", | ||
| options=[(v, v) for v in variable_names], | ||
| style={"flexGrow": 0, "minWidth": 120}, | ||
| multiple=True, | ||
| tooltip="Select the variables of the test dataset", | ||
| ) | ||
| control_group = Box( | ||
| style={ | ||
| "display": "flex", | ||
| "flexDirection": "row", | ||
| "padding": 4, | ||
| "justifyContent": "center", | ||
| "gap": 4, | ||
| }, | ||
| children=[select], | ||
| ) | ||
|
|
||
| text = update_info_text(ctx, selected_dataset_id) | ||
| info_text = Typography(id="info_text", children=text) | ||
|
|
||
| return Box( | ||
| style={ | ||
| "display": "flex", | ||
| "flexDirection": "column", | ||
| "width": "100%", | ||
| "height": "100%", | ||
| }, | ||
| children=[info_text, control_group], | ||
| ) | ||
|
|
||
|
|
||
| def get_variable_names( | ||
| dataset: pd.DataFrame, | ||
| prev_var_name: str | None = None, | ||
| ) -> tuple[list[str], list[str]]: | ||
| """Get the variable names and the selected variable name | ||
| for the given dataset and previously selected variable name. | ||
| """ | ||
|
|
||
| if dataset is not None: | ||
| var_names = [v for v in dataset.keys() if v != "x"] | ||
| else: | ||
| var_names = [] | ||
|
|
||
| if prev_var_name and prev_var_name in var_names: | ||
| var_name = prev_var_name | ||
| elif var_names: | ||
| var_name = var_names[0] | ||
| else: | ||
| var_name = "" | ||
|
|
||
| return var_names, var_name | ||
|
|
||
|
|
||
| @panel.callback( | ||
| Input("@app", "selectedDatasetId"), | ||
| Input("selected_variable_name", "value"), | ||
| Output("info_text", "children"), | ||
| ) | ||
| def update_info_text( | ||
| ctx: Context, | ||
| dataset_id: str = "", | ||
| selected_var_names: list[str] | None = None, | ||
| ) -> list[str]: | ||
|
|
||
| if selected_var_names is not None: | ||
| text = ", ".join(map(str, selected_var_names)) | ||
| return [f"The dataset is {dataset_id} and the selected variables are: {text}"] | ||
| else: | ||
| return [f"The dataset is {dataset_id} and no variables are selected."] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer if we limit the number of demo's here, as there is already some backlog with a few more demos. It would be good, if we can add your demo to
Panel Cas it already has a Select element, and you can now show that we can use multiple elements by updating the text accordingly (which is also very similar to your demo).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer, if no longer continue that way. In another pull request we should rearrange the demo app entirely.