Skip to content

Commit 9fbfb2e

Browse files
committed
Make examples more readable:
1 parent 584284f commit 9fbfb2e

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

shiny/api-examples/MarkdownStream/app-core.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@
1111

1212
def server(input, output, session):
1313
# Read in the README.md file from the py-shiny repository
14-
response = requests.get(
14+
readme = requests.get(
1515
"https://raw.githubusercontent.com/posit-dev/py-shiny/refs/heads/main/README.md"
1616
)
17-
content = response.text.replace("\n", " \n ")
17+
readme_chunks = readme.text.replace("\n", " \n ").split(" ")
1818

1919
# Generate words from the README.md file (with a small delay)
20-
def generate_words():
21-
for word in content.split(" "):
20+
def chunk_generator():
21+
for chunk in readme_chunks:
2222
time.sleep(0.05)
23-
yield word + " "
23+
yield chunk + " "
2424

2525
md = ui.MarkdownStream("shiny-readme")
2626
md.ui()
27-
md.stream(generate_words())
27+
md.stream(chunk_generator())
2828

2929

3030
app = App(app_ui, server)

shiny/api-examples/MarkdownStream/app-express.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55
from shiny.express import session, ui
66

77
# Read in the README.md file from the py-shiny repository
8-
response = requests.get(
8+
readme = requests.get(
99
"https://raw.githubusercontent.com/posit-dev/py-shiny/refs/heads/main/README.md"
1010
)
11-
content = response.text.replace("\n", " \n ")
11+
readme_chunks = readme.text.replace("\n", " \n ").split(" ")
1212

1313

1414
# Generate words from the README.md file (with a small delay)
15-
def generate_words():
16-
for word in content.split(" "):
15+
def chunk_generator():
16+
for chunk in readme_chunks:
1717
if not session.is_stub_session():
1818
time.sleep(0.05)
19-
yield word + " "
19+
yield chunk + " "
2020

2121

2222
md = ui.MarkdownStream("shiny-readme")
2323
md.ui()
24-
md.stream(generate_words())
24+
md.stream(chunk_generator())

0 commit comments

Comments
 (0)