Skip to content

Commit

Permalink
Update data so that redefine can be called multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Kuethe committed Feb 12, 2024
1 parent 8f4c0d7 commit 32e895c
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
22 changes: 22 additions & 0 deletions docs/examples/playground/app1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from htmltools import a
from shiny.express import ui
from shinyobservable import Observable, ObservableRenderer

# NOTEBOOK = "https://observablehq.com/@d3/zoomable-sunburst"
NOTEBOOK = "https://observablehq.com/@eoda/test"

ui.h1("Observable Notebook in Shiny")
ui.div(a(NOTEBOOK, href=NOTEBOOK, target="_blank"))
ui.hr()


# Embed selected cells
@ObservableRenderer
def render_cells():
return Observable(NOTEBOOK, cells=[2, 3, 4])


# Include entire notebook
# @ObservableRenderer
def render_notebook():
return Observable(NOTEBOOK)
27 changes: 27 additions & 0 deletions docs/examples/playground/app2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from htmltools import a
from shiny.express import ui
from shinyobservable import Observable, ObservableRenderer

NOTEBOOK = "https://observablehq.com/@eoda/playground"

ui.h1("Observable Notebook in Shiny")
ui.div(a(NOTEBOOK, href=NOTEBOOK, target="_blank"))
ui.hr()


# Embed selected cells
@ObservableRenderer
def render_cells():
return (
Observable(NOTEBOOK, cells=["viewof echart", "echart"])
.redefine(
chartData=dict(x=["A", "B", "C", "D", "E"], y=[100, 150, 120, 40, 80])
)
.redefine(lineColor="green")
)


# Include entire notebook
# @ObservableRenderer
def render_notebook():
return Observable(NOTEBOOK)
2 changes: 1 addition & 1 deletion shinyobservable/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def redefine(self, **kwargs) -> Observable:
... )
>>>
"""
self.data = kwargs
self.data.update(kwargs)
return self

def to_dict(self):
Expand Down

0 comments on commit 32e895c

Please sign in to comment.