-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Stefan Kuethe
committed
Feb 12, 2024
1 parent
4f10898
commit f767e21
Showing
16 changed files
with
986 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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 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,9 @@ | ||
# API Docs | ||
|
||
::: shinyobservable.Observable | ||
|
||
::: shinyobservable.ObservableRenderer | ||
|
||
::: shinyobservable.output_observable | ||
|
||
::: shinyobservable.ObservableContext |
This file contains 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 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,48 @@ | ||
import random | ||
import string | ||
|
||
from htmltools import a | ||
from shiny import reactive | ||
from shiny.express import input, ui | ||
from shinyobservable import Observable, ObservableContext, ObservableRenderer | ||
|
||
NOTEBOOK = "https://observablehq.com/@d3/bar-chart-transitions/2" | ||
|
||
ui.h1("Observable Notebook in Shiny") | ||
ui.div(a(NOTEBOOK, href=NOTEBOOK, target="_blank")) | ||
ui.hr() | ||
|
||
|
||
def create_data(): | ||
return [ | ||
dict(letter=letter, frequency=random.uniform(0, 1)) | ||
for letter in string.ascii_uppercase[ | ||
random.randint(0, 3) : random.randint(20, 25) | ||
] | ||
] | ||
|
||
|
||
cells = ["viewof order", "chart", "data"] | ||
|
||
|
||
@ObservableRenderer | ||
def render_notebook(): | ||
return Observable(NOTEBOOK, cells=cells).redefine( | ||
# data=create_data(), | ||
data=[ | ||
dict(letter="A", frequency=0.1), | ||
dict(letter="B", frequency=0.8), | ||
dict(letter="C", frequency=0.6), | ||
], | ||
) | ||
|
||
|
||
with ui.div(style="padding-top: 10px;"): | ||
ui.input_action_button("update_data", "Update data") | ||
|
||
|
||
@reactive.Effect | ||
@reactive.event(input.update_data) | ||
async def update_data(): | ||
async with ObservableContext("render_notebook") as nb: | ||
nb.redefine(data=create_data()) |
This file contains 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,22 @@ | ||
import requests | ||
from htmltools import a | ||
from shiny.express import ui | ||
from shinyobservable import Observable, ObservableRenderer | ||
|
||
NOTEBOOK = "https://observablehq.com/@d3/zoomable-sunburst" | ||
|
||
data = requests.get( | ||
"https://raw.githubusercontent.com/observablehq/examples/main/custom-data/population.json" | ||
).json() | ||
|
||
print(data) | ||
|
||
ui.h1("Observable Notebook in Shiny") | ||
ui.div(a(NOTEBOOK, href=NOTEBOOK, target="_blank")) | ||
ui.hr() | ||
|
||
|
||
@ObservableRenderer | ||
def render_cells(): | ||
# Update the 'data' cell with the data downloaded above | ||
return Observable(NOTEBOOK, cells=["chart"]).redefine(data=data) |
This file contains 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,3 @@ | ||
```python | ||
-8<-- "getting_started/interactivity.py" | ||
``` |
This file contains 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,3 @@ | ||
```python | ||
-8<-- "getting_started/redefine_data.py" | ||
``` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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,32 @@ | ||
# Welcome to Shinyobservable | ||
|
||
Embed [Observable Notebooks](https://observablehq.com/) in [Shiny for Python](https://shiny.posit.co/py/). | ||
|
||
[Shinyobservable](https://github.com/eodaGmbH/py-shiny-observable) makes it a breeze to integrate libraries such as [D3](https://d3js.org/). | ||
|
||
Create any kind of JavaScript visualizations and let Shiny handle your data and interactivity. | ||
|
||
## Features | ||
|
||
* Embed entire notebooks | ||
* Embed selected cells only | ||
* Update data cells to update visualizations | ||
|
||
## Installation | ||
|
||
```bash | ||
pip install shinyobservable | ||
|
||
# Dev | ||
pip install git+https://github.com/eodaGmbH/py-shiny-shinyobservable | ||
``` | ||
|
||
## Quickstart | ||
|
||
```python | ||
-8<-- "getting_started/basic_usage.py" | ||
``` | ||
|
||
Enjoy your notebook! | ||
|
||
![](images/chart-cell.png) |
This file contains 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,43 @@ | ||
site_name: Shinyobservable | ||
|
||
theme: | ||
name: material | ||
palette: | ||
primary: "green" | ||
features: | ||
- navigation.tabs | ||
- navigation.tabs.sticky | ||
|
||
nav: | ||
- Getting Started: | ||
- Welcome to Shinyobservable: index.md | ||
- Redefine data cells: getting_started/redefine_data.md | ||
- Interactivity: getting_started/interactivity.md | ||
- API Documentation: api.md | ||
|
||
markdown_extensions: | ||
- attr_list | ||
- md_in_html | ||
- pymdownx.highlight: | ||
anchor_linenums: true | ||
line_spans: __span | ||
pygments_lang_class: true | ||
- pymdownx.inlinehilite: | ||
- pymdownx.superfences: | ||
- pymdownx.snippets: | ||
check_paths: true | ||
base_path: [docs/examples, "."] | ||
|
||
plugins: | ||
- search: | ||
- mkdocstrings: | ||
handlers: | ||
python: | ||
options: | ||
docstring_style: google | ||
docstring_section_style: table | ||
show_root_heading: true | ||
show_source: true | ||
|
||
watch: | ||
- shinyobservable |
Oops, something went wrong.