-
Notifications
You must be signed in to change notification settings - Fork 147
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
base: master
Are you sure you want to change the base?
Changes from all commits
8227e63
5b46d24
9b8c598
f6b78c0
a0423cc
0781007
daa6e65
7d8733a
3d2ddb9
5c9d15e
2bcf2e8
a2c5625
ad04dad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -53,25 +53,26 @@ | |||||||||||||
|
||||||||||||||
@solara.component | ||||||||||||||
def Page(): | ||||||||||||||
option, set_option = solara.use_state("bars") | ||||||||||||||
click_data, set_click_data = solara.use_state(None) | ||||||||||||||
mouseover_data, set_mouseover_data = solara.use_state(None) | ||||||||||||||
mouseout_data, set_mouseout_data = solara.use_state(None) | ||||||||||||||
option = solara.use_reactive("bars") | ||||||||||||||
click_data = solara.use_reactive(None) | ||||||||||||||
mouseover_data = solara.use_reactive(None) | ||||||||||||||
mouseout_data = solara.use_reactive(None) | ||||||||||||||
|
||||||||||||||
with solara.VBox() as main: | ||||||||||||||
with solara.Card("Echarts"): | ||||||||||||||
with solara.ToggleButtonsSingle("bars", on_value=set_option): | ||||||||||||||
solara.Button("bars") | ||||||||||||||
solara.Button("pie") | ||||||||||||||
solara.FigureEcharts( | ||||||||||||||
option=options[option], on_click=set_click_data, on_mouseover=set_mouseover_data, on_mouseout=set_mouseout_data, responsive=True | ||||||||||||||
) | ||||||||||||||
with solara.Card("Event data"): | ||||||||||||||
solara.Markdown(f"**Click data**: {click_data}") | ||||||||||||||
solara.Markdown(f"**Mouseover data**: {mouseover_data}") | ||||||||||||||
solara.Markdown(f"**Mouseout data**: {mouseout_data}") | ||||||||||||||
|
||||||||||||||
return main | ||||||||||||||
with solara.Card("Echarts"): | ||||||||||||||
with solara.ToggleButtonsSingle(value=option.value, on_value=lambda data: setattr(option, "value", data)): | ||||||||||||||
solara.Button("bars", value="bars") | ||||||||||||||
solara.Button("pie", value="pie") | ||||||||||||||
solara.FigureEcharts( | ||||||||||||||
option=options[option.value], | ||||||||||||||
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), | ||||||||||||||
Comment on lines
+67
to
+69
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can use
Suggested change
|
||||||||||||||
responsive=True, | ||||||||||||||
) | ||||||||||||||
with solara.Card("Event data"): | ||||||||||||||
solara.Markdown(f"**Click data**: {click_data.value}") | ||||||||||||||
solara.Markdown(f"**Mouseover data**: {mouseover_data.value}") | ||||||||||||||
solara.Markdown(f"**Mouseout data**: {mouseout_data.value}") | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
__doc__ += apidoc(solara.FigureEcharts.f) # type: ignore |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,20 +11,18 @@ | |
|
||
@solara.component | ||
def Page(): | ||
freq, set_freq = solara.use_state(2.0) | ||
phase, set_phase = solara.use_state(0.1) | ||
freq = solara.use_reactive(2.0) | ||
phase = solara.use_reactive(0.1) | ||
y = np.sin(x * freq + phase) | ||
|
||
fig = Figure() | ||
ax = fig.subplots() | ||
ax.plot(x, y) | ||
ax.set_ylim(-1.2, 1.2) | ||
|
||
with solara.VBox() as main: | ||
solara.FloatSlider("Frequency", value=freq, on_value=set_freq, min=0, max=10) | ||
solara.FloatSlider("Phase", value=phase, on_value=set_phase, min=0, max=np.pi, step=0.1) | ||
solara.FigureMatplotlib(fig, dependencies=[freq, phase]) | ||
return main | ||
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) | ||
Comment on lines
+23
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also use |
||
solara.FigureMatplotlib(fig, dependencies=[freq, phase]) | ||
|
||
|
||
__doc__ += apidoc(solara.FigureMatplotlib.f) # type: ignore |
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 think for simplicity we can just use
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.
Also, for future reference, instead of
setattr(option, "value", data)
, you can just use the reactive variables' set function, i.e.option.set(data)