Skip to content

Commit ea82e3d

Browse files
committed
w
1 parent f808c35 commit ea82e3d

212 files changed

Lines changed: 125832 additions & 7073 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.DS_Store

-2 KB
Binary file not shown.

Publish/.DS_Store

8 KB
Binary file not shown.

Publish/1 Shiny/.DS_Store

6 KB
Binary file not shown.

Publish/1 Shiny/1 shiny intro.qmd

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
---
2+
title: "shiny in Python introduction"
3+
author: "Tony Duan"
4+
execute:
5+
warning: false
6+
error: false
7+
8+
9+
format:
10+
html:
11+
toc: true
12+
toc-location: right
13+
code-fold: show
14+
code-tools: true
15+
16+
code-block-bg: true
17+
code-block-border-left: "#31BAE9"
18+
code-copy: true
19+
20+
21+
filters:
22+
- shinylive
23+
24+
---
25+
26+
27+
```{python}
28+
#| eval: false
29+
pip install shiny
30+
```
31+
32+
33+
# if using shinylive(shiny without server) then install extension in your Quarto project
34+
35+
```{python}
36+
#| eval: false
37+
quarto add quarto-ext/shinylive
38+
```
39+
40+
41+
# Add filters in YAML header
42+
43+
````
44+
---
45+
46+
filters:
47+
- shinylive
48+
49+
---
50+
````
51+
52+
# Shiny code
53+
54+
````
55+
56+
```{shinylive-python}
57+
#| standalone: true
58+
59+
from shiny import *
60+
61+
app_ui = ui.page_fluid(
62+
ui.input_slider("n", "N", 0, 100, 40),
63+
ui.output_text_verbatim("txt"),
64+
)
65+
66+
67+
def server(input, output, session):
68+
@output
69+
@render.text
70+
def txt():
71+
return f"The value of n*2 is {input.n() * 2}"
72+
73+
app = App(app_ui, server)
74+
```
75+
76+
````
77+
78+
```{shinylive-python}
79+
#| standalone: true
80+
81+
from shiny import *
82+
83+
app_ui = ui.page_fluid(
84+
ui.input_slider("n", "N", 0, 100, 40),
85+
ui.output_text_verbatim("txt"),
86+
)
87+
88+
89+
def server(input, output, session):
90+
@output
91+
@render.text
92+
def txt():
93+
return f"The value of n*2 is {input.n() * 2}"
94+
95+
app = App(app_ui, server)
96+
```
97+
98+
99+
100+
101+
# Reference
102+
103+
https://shiny.posit.co/py/get-started/shinylive.html
104+

Publish/2 quarto/.DS_Store

6 KB
Binary file not shown.
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
---
2+
title: "Using marimo python in quarto"
3+
author: "Tony Duan"
4+
execute:
5+
warning: false
6+
error: false
7+
8+
9+
format:
10+
html:
11+
toc: true
12+
toc-location: right
13+
code-fold: show
14+
code-tools: true
15+
16+
code-block-bg: true
17+
code-block-border-left: "#31BAE9"
18+
code-copy: true
19+
20+
21+
filters:
22+
- marimo-team/marimo
23+
---
24+
25+
26+
```{r}
27+
library(reticulate)
28+
py_require(c("wigglystuff","marimo"))
29+
```
30+
31+
32+
# Uinsg marimo in quarto
33+
34+
## Add quarto-marimo to your project
35+
36+
37+
```{base}
38+
quarto add marimo-team/quarto-marimo
39+
```
40+
41+
42+
## Add filters in YAML header
43+
44+
````
45+
---
46+
filters:
47+
- marimo-team/marimo
48+
---
49+
````
50+
51+
52+
53+
# add code in quaro
54+
55+
## slider bar
56+
57+
```python {.marimo}
58+
#| echo: true
59+
import marimo as mo
60+
slider = mo.ui.slider(1, 500, 1, label="Look, a slider!",full_width=True)
61+
slider
62+
```
63+
64+
print out slider value
65+
66+
```python {.marimo}
67+
#| echo: true
68+
slider.value
69+
```
70+
71+
print out slider value number of 🍃
72+
73+
74+
```python {.marimo}
75+
#| echo: true
76+
mo.md("🍃" * slider.value + "~~~~!")
77+
```
78+
79+
## slider number
80+
81+
```python {.marimo}
82+
#| echo: true
83+
from wigglystuff import TangleSlider
84+
85+
coffees = mo.ui.anywidget(
86+
TangleSlider(amount=10.0, min_value=0.0, step=1, suffix=" coffees" , digits=0)
87+
)
88+
89+
price = mo.ui.anywidget(
90+
TangleSlider(amount=3.50, min_value=0.01, max_value=10, step=0.01, prefix="$",digits=2
91+
)
92+
93+
)
94+
95+
```
96+
97+
98+
```python {.marimo}
99+
#| echo: true
100+
total = coffees.amount * price.amount
101+
total
102+
```
103+
104+
105+
106+
107+
```python {.marimo}
108+
#| echo: true
109+
mo.md(f"""
110+
### coffee billing:
111+
112+
you have {coffees} with {price} and the total spending is ${total:.2f}
113+
"""
114+
)
115+
```
116+
117+
118+
# Reference
119+
120+
https://github.com/marimo-team/quarto-marimo

_extensions/.DS_Store

6 KB
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
title: Quarto Marimo Extension
2+
version: 0.4.2
3+
quarto-required: ">=1.3.0"
4+
contributes:
5+
filters:
6+
- marimo-execute.lua
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env python3
2+
3+
import json
4+
import sys
5+
import tempfile
6+
from textwrap import dedent
7+
8+
try:
9+
from marimo._cli.sandbox import construct_uv_flags
10+
from marimo._utils.inline_script_metadata import PyProjectReader
11+
except ImportError as e:
12+
try:
13+
from marimo._cli.sandbox import ( # type: ignore[attr-defined, no-redef]
14+
PyProjectReader,
15+
construct_uv_flags,
16+
)
17+
except ImportError:
18+
from marimo import __version__
19+
20+
raise ImportError(
21+
"Potential version incompatibility quartom-marimo requires marimo "
22+
f">=0.13.3. marimo version {__version__} is detected. "
23+
) from e
24+
25+
26+
def extract_command(header: str) -> list[str]:
27+
if not header.startswith("#"):
28+
header = "\n# ".join(["# /// script", *header.splitlines(), "///"])
29+
pyproject = PyProjectReader.from_script(header)
30+
with tempfile.NamedTemporaryFile(
31+
mode="w", delete=False, suffix=".txt"
32+
) as temp_file:
33+
flags = construct_uv_flags(pyproject, temp_file, [], [])
34+
35+
return ["run"] + flags
36+
37+
38+
if __name__ == "__main__":
39+
assert len(sys.argv) == 1, f"Unexpected call format got {sys.argv}"
40+
41+
header = dedent(sys.stdin.read())
42+
43+
command = extract_command(header)
44+
sys.stdout.write(json.dumps(command))

0 commit comments

Comments
 (0)