File tree Expand file tree Collapse file tree 2 files changed +12
-12
lines changed
shiny/api-examples/MarkdownStream Expand file tree Collapse file tree 2 files changed +12
-12
lines changed Original file line number Diff line number Diff line change 11
11
12
12
def server (input , output , session ):
13
13
# Read in the README.md file from the py-shiny repository
14
- response = requests .get (
14
+ readme = requests .get (
15
15
"https://raw.githubusercontent.com/posit-dev/py-shiny/refs/heads/main/README.md"
16
16
)
17
- content = response .text .replace ("\n " , " \n " )
17
+ readme_chunks = readme .text .replace ("\n " , " \n " ). split ( " " )
18
18
19
19
# 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 :
22
22
time .sleep (0.05 )
23
- yield word + " "
23
+ yield chunk + " "
24
24
25
25
md = ui .MarkdownStream ("shiny-readme" )
26
26
md .ui ()
27
- md .stream (generate_words ())
27
+ md .stream (chunk_generator ())
28
28
29
29
30
30
app = App (app_ui , server )
Original file line number Diff line number Diff line change 5
5
from shiny .express import session , ui
6
6
7
7
# Read in the README.md file from the py-shiny repository
8
- response = requests .get (
8
+ readme = requests .get (
9
9
"https://raw.githubusercontent.com/posit-dev/py-shiny/refs/heads/main/README.md"
10
10
)
11
- content = response .text .replace ("\n " , " \n " )
11
+ readme_chunks = readme .text .replace ("\n " , " \n " ). split ( " " )
12
12
13
13
14
14
# 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 :
17
17
if not session .is_stub_session ():
18
18
time .sleep (0.05 )
19
- yield word + " "
19
+ yield chunk + " "
20
20
21
21
22
22
md = ui .MarkdownStream ("shiny-readme" )
23
23
md .ui ()
24
- md .stream (generate_words ())
24
+ md .stream (chunk_generator ())
You can’t perform that action at this time.
0 commit comments