99# Can use `dict` in python >= 3.9
1010from typing import (
1111 TYPE_CHECKING ,
12+ Any ,
1213 Callable ,
1314 Literal ,
1415 Optional ,
4647
4748__all__ = (
4849 "text" ,
50+ "code" ,
4951 "plot" ,
5052 "image" ,
5153 "table" ,
@@ -61,6 +63,17 @@ class text(Renderer[str]):
6163 """
6264 Reactively render text.
6365
66+ When used in Shiny Express applications, this defaults to displaying the text as
67+ normal text on the web page. When used in Shiny Core applications, this should be
68+ paired with :func:`~shiny.ui.output_text` in the UI.
69+
70+
71+ Parameters
72+ ----------
73+ inline
74+ Used in Shiny Express only. If ``True``, the result is displayed inline. (This
75+ argument is passed to :func:`~shiny.ui.output_text`.)
76+
6477 Returns
6578 -------
6679 :
@@ -74,14 +87,92 @@ class text(Renderer[str]):
7487
7588 See Also
7689 --------
90+ ~shiny.render.code
7791 ~shiny.ui.output_text
7892 """
7993
80- def default_ui (self , id : str , placeholder : bool | MISSING_TYPE = MISSING ) -> Tag :
94+ def default_ui (
95+ self ,
96+ id : str ,
97+ * ,
98+ inline : bool | MISSING_TYPE = MISSING ,
99+ ) -> Tag :
100+ kwargs : dict [str , Any ] = {}
101+ set_kwargs_value (kwargs , "inline" , inline , self .inline )
102+
103+ return _ui .output_text (id , ** kwargs )
104+
105+ def __init__ (
106+ self ,
107+ _fn : Optional [ValueFn [str ]] = None ,
108+ * ,
109+ inline : bool = False ,
110+ ) -> None :
111+ super ().__init__ (_fn )
112+ self .inline = inline
113+
114+ async def transform (self , value : str ) -> Jsonifiable :
115+ return str (value )
116+
117+
118+ # ======================================================================================
119+ # RenderCode
120+ # ======================================================================================
121+
122+
123+ class code (Renderer [str ]):
124+ """
125+ Reactively render text as code (monospaced).
126+
127+ When used in Shiny Express applications, this defaults to displaying the text in a
128+ monospace font in a code block. When used in Shiny Core applications, this should be
129+ paired with :func:`~shiny.ui.output_text_verbatim` in the UI.
130+
131+ Parameters
132+ ----------
133+ placeholder
134+ Used in Shiny Express only. If the output is empty or ``None``, should an empty
135+ rectangle be displayed to serve as a placeholder? This does not affect behavior
136+ when the output is nonempty. (This argument is passed to
137+ :func:`~shiny.ui.output_text_verbatim`.)
138+
139+
140+ Returns
141+ -------
142+ :
143+ A decorator for a function that returns a string.
144+
145+ Tip
146+ ----
147+ The name of the decorated function (or ``@output(id=...)``) should match the ``id``
148+ of a :func:`~shiny.ui.output_text_verbatim` container (see
149+ :func:`~shiny.ui.output_text_verbatim` for example usage).
150+
151+ See Also
152+ --------
153+ ~shiny.render.text
154+ ~shiny.ui.output_text_verbatim
155+ """
156+
157+ def default_ui (
158+ self ,
159+ id : str ,
160+ * ,
161+ placeholder : bool | MISSING_TYPE = MISSING ,
162+ ) -> Tag :
81163 kwargs : dict [str , bool ] = {}
82- set_kwargs_value (kwargs , "placeholder" , placeholder , None )
164+ set_kwargs_value (kwargs , "placeholder" , placeholder , self . placeholder )
83165 return _ui .output_text_verbatim (id , ** kwargs )
84166
167+ def __init__ (
168+ self ,
169+ _fn : Optional [ValueFn [str ]] = None ,
170+ * ,
171+ placeholder : bool = False ,
172+ ) -> None :
173+ super ().__init__ (_fn )
174+ self .placeholder = placeholder
175+
85176 async def transform (self , value : str ) -> Jsonifiable :
86177 return str (value )
87178
0 commit comments