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

docs update code in viz_folder #916

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

lizzy985
Copy link
Contributor

@lizzy985 lizzy985 commented Dec 8, 2024

No description provided.

@lizzy985
Copy link
Contributor Author

lizzy985 commented Dec 8, 2024

I closed and deleted old PR, and this is new PR and already fix the code you mentioned in old PR. If there is still any issue, please let me know. Thank you.

@maartenbreddels maartenbreddels force-pushed the master branch 2 times, most recently from cded5b2 to 32af76f Compare December 20, 2024 12:52
Comment on lines 34 to 38
on_selection=lambda data: state.value.update({"selection_data": data}),
on_click=lambda data: state.value.update({"click_data": data}),
on_hover=lambda data: state.value.update({"hover_data": data}),
on_unhover=lambda data: state.value.update({"unhover_data": data}),
on_deselect=lambda data: state.value.update({"deselect_data": data}),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .update method on a dictionary mutates that dictionary, which means that this won't result in the state being updated. Instead, we should explicitly .set the state with the previous values and the new value, i.e.

Suggested change
on_selection=lambda data: state.value.update({"selection_data": data}),
on_click=lambda data: state.value.update({"click_data": data}),
on_hover=lambda data: state.value.update({"hover_data": data}),
on_unhover=lambda data: state.value.update({"unhover_data": data}),
on_deselect=lambda data: state.value.update({"deselect_data": data}),
on_selection=lambda data: state.set({**state.value, "selection_data": data}),
on_click=lambda data: state.set({**state.value, "click_data": data}),
on_hover=lambda data: state.set({**state.value, "hover_data": data}),
on_unhover=lambda data: state.set({**state.value, "unhover_data": data}),
on_deselect=lambda data: state.set({**state.value, "deselect_data": data}),

@@ -58,20 +58,15 @@ def Page():
mouseover_data, set_mouseover_data = solara.use_state(None)
mouseout_data, set_mouseout_data = solara.use_state(None)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should convert these to use_reactive as well.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's also a couple use_states still around in this file, but I'm not able to comment directly on those lines it seems.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I already fix these issues, if there is still any problem, please let me know.


return main
with solara.Card("Echarts"):
with solara.ToggleButtonsSingle(value=option.value, on_value=lambda data: setattr(option, "value", data)):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for simplicity we can just use

Suggested change
with solara.ToggleButtonsSingle(value=option.value, on_value=lambda data: setattr(option, "value", data)):
with solara.ToggleButtonsSingle(value=option):

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, for future reference, instead of setattr(option, "value", data), you can just use the reactive variables' set function, i.e. option.set(data)

Comment on lines +67 to +69
on_click=lambda e: setattr(click_data, "value", e),
on_mouseover=lambda e: setattr(mouseover_data, "value", e),
on_mouseout=lambda e: setattr(mouseout_data, "value", e),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use click_data.set and so on for these. Since we don't have to do anything to the data, we can just assign the set functions directly:

Suggested change
on_click=lambda e: setattr(click_data, "value", e),
on_mouseover=lambda e: setattr(mouseover_data, "value", e),
on_mouseout=lambda e: setattr(mouseout_data, "value", e),
on_click=click_data.set,
on_mouseover=mouseover_data.set,
on_mouseout=mouseout_data.set,

Comment on lines +23 to +24
solara.FloatSlider("Frequency", value=freq.value, on_value=lambda v: setattr(freq, "value", v), min=0, max=10)
solara.FloatSlider("Phase", value=phase.value, on_value=lambda v: setattr(phase, "value", v), min=0, max=np.pi, step=0.1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also use .set here.

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.

2 participants