Skip to content

Commit

Permalink
Address feedback from PR #285
Browse files Browse the repository at this point in the history
  • Loading branch information
itepifanio committed Sep 20, 2023
1 parent 52c7b5e commit b71aeff
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 121 deletions.
10 changes: 5 additions & 5 deletions solara/components/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,13 @@ def on_points_callback(data):
)

def update_data():
fig_widget = solara.get_widget(fig_element)
fig_widget: FigureWidget = solara.get_widget(fig_element)
fig_widget.layout = fig.layout

length = len(fig_widget.data)
fig_widget.add_traces(fig.data)
if hasattr(fig_widget, 'data'):
length = len(fig_widget.data)
data = list(fig_widget.data)
fig_widget.data = data[length:]
data = list(fig_widget.data)
fig_widget.data = data[length:]

solara.use_effect(update_data, dependencies or fig)
return fig_element
Expand Down
5 changes: 3 additions & 2 deletions solara/website/pages/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from solara.alias import rv
from solara.components.title import Title

from ..components import Header, Hero
#from ..components import Header, Hero


title = "Home"
Expand Down Expand Up @@ -85,6 +85,7 @@ def Layout(children=[]):
solara.Meta(property="og:url", content="https://solara.dev" + router.path)
solara.Meta(property="og:image", content="https://solara.dev/static/assets/images/logo-small.png")
solara.Meta(property="og:type", content="website")
"""
Header(
on_toggle_left_menu=lambda: set_show_left_menu(not show_left_menu),
on_toggle_right_menu=lambda: set_show_right_menu(not show_right_menu),
Expand All @@ -95,7 +96,7 @@ def Layout(children=[]):
sub_title="Solara helps you build powerful & scalable Jupyter and web apps <b>faster</b> and <b>easier</b>.",
button_text="Quickstart",
)

"""
with rv.Container(tag="section", fluid=True, ma_0=True, pa_0=True, class_="fill-height mb-8 solara-content-main"):
if route_current is not None and route_current.path == "/":
description = "Use ipywidgets with Solara to build powerful and scalable web apps for Jupyter and production in Python."
Expand Down
44 changes: 0 additions & 44 deletions solara/website/pages/api/altair.py

This file was deleted.

55 changes: 29 additions & 26 deletions solara/website/pages/examples/visualization/annotator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""# Image annotation with Solara
This example displays how to annotate images with different drawing tools in plotly figures. Use the canvas
This example displays how to annotate images with different drawing tools in plotly figures. Use the canvas
below to draw shapes and visualize the canvas callback.
Expand All @@ -12,7 +12,7 @@
import solara

title = "Plotly Image Annotator"
text = solara.reactive('Draw on canvas')
shapes = solara.reactive(None)

class CustomEncoder(json.JSONEncoder):
def default(self, o):
Expand All @@ -24,34 +24,37 @@ def default(self, o):
@solara.component
def Page():
def on_relayout(data):
print(data)
if data is None:
return

relayout_data = data['relayout_data']

if "shapes" in relayout_data:
text.value = str(json.dumps(relayout_data["shapes"], indent=2, cls=CustomEncoder))

with solara.Div() as main:

fig = go.FigureWidget(
layout=go.Layout(
showlegend=False,
autosize=False,
width=600,
height=600,
modebar={
"add": [
"drawclosedpath",
"drawcircle",
"drawrect",
"eraseshape",
]
}
)
shapes.value = relayout_data["shapes"]

fig = go.FigureWidget(
layout=go.Layout(
showlegend=False,
autosize=False,
width=600,
height=600,
modebar={
"add": [
"drawclosedpath",
"drawcircle",
"drawrect",
"eraseshape",
]
}
)

solara.FigurePlotly(fig, on_relayout=on_relayout)
solara.Preformatted(text.value)

return main
)

solara.FigurePlotly(fig, on_relayout=on_relayout)

if not shapes.value:
solara.Markdown("## Draw on the canvas")
else:
solara.Markdown("## Data returned by drawing")
formatted_shapes = str(json.dumps(shapes.value, indent=2, cls=CustomEncoder))
solara.Preformatted(formatted_shapes)
44 changes: 0 additions & 44 deletions solara/website/pages/examples/visualization/plotly.py

This file was deleted.

0 comments on commit b71aeff

Please sign in to comment.