77import matplotlib .pyplot as plt
88import numpy as np
99
10- from shiny import App , Inputs , Outputs , Session , ui
10+ from shiny import App , Inputs , Outputs , Session , render , ui
1111
1212
1313def make_example (id : str , label : str , title : str , desc : str , extra : Any = None ):
@@ -77,7 +77,7 @@ def make_example(id: str, label: str, title: str, desc: str, extra: Any = None):
7777
7878
7979def server (input : Inputs , output : Outputs , session : Session ):
80- @session .download ()
80+ @render .download ()
8181 def download1 ():
8282 """
8383 This is the simplest case. The implementation simply returns the name of a file.
@@ -88,12 +88,12 @@ def download1():
8888 path = os .path .join (os .path .dirname (__file__ ), "mtcars.csv" )
8989 return path
9090
91- @session .download (filename = "image.png" )
91+ @render .download (filename = "image.png" )
9292 def download2 ():
9393 """
9494 Another way to implement a file download is by yielding bytes; either all at
9595 once, like in this case, or by yielding multiple times. When using this
96- approach, you should pass a filename argument to @session .download, which
96+ approach, you should pass a filename argument to @render .download, which
9797 determines what the browser will name the downloaded file.
9898 """
9999
@@ -107,7 +107,7 @@ def download2():
107107 plt .savefig (buf , format = "png" )
108108 yield buf .getvalue ()
109109
110- @session .download (
110+ @render .download (
111111 filename = lambda : f"新型-{ date .today ().isoformat ()} -{ np .random .randint (100 ,999 )} .csv"
112112 )
113113 async def download3 ():
@@ -116,7 +116,8 @@ async def download3():
116116 yield "新,1,2\n "
117117 yield "型,4,5\n "
118118
119- @session .download (id = "download4" , filename = "failuretest.txt" )
119+ @output (id = "download4" )
120+ @render .download (filename = "failuretest.txt" )
120121 async def _ ():
121122 yield "hello"
122123 raise Exception ("This error was caused intentionally" )
0 commit comments