Verbatim Text
#| standalone: true
#| components: [viewer]
#| viewerHeight: 200
from shiny import App, render, ui
app_ui = ui.page_fluid(
ui.input_text("Text", "Enter text", "Hello Shiny"),
ui.output_text_verbatim("text"),
)
def server(input, output, session):
@render.text
def text():
return input.Text()
app = App(app_ui, server)
Relevant Functions
-
ui.output_text_verbatim
ui.output_text_verbatim(id, placeholder=False)
-
@render.text
render.text(fn=None)
Details
Verbatim text displays a character string as monospaced code in a shaded rectangle.
To create reactive verbatim text, render the text in the server function with the decorators @render.text
, just as you would to display normal text. Then place the rendered text in the ui with ui.output_verbatim_text()
.
By default, ui.output_verbatim_text()
will display nothing when the string to display is empty. To ensure that ui.output_verbatim_text()
displays an empty shaded rectangle as a placeholder even when when the string to display is empty, set placeholder=True
.
See Text to display string values as normal text.
Variations
Placeholder rectangle when string is empty
Verbatim text with a placeholder when the string to display is empty (see Details above).
#| standalone: true
#| components: [viewer]
#| viewerHeight: 300
from shiny import App, render, ui
app_ui = ui.page_fluid(
ui.input_text("Text", "Enter Text", ""),
ui.output_text_verbatim("text", placeholder=True),
)
def server(input, output, session):
@render.text
def text():
return input.Text()
app = App(app_ui, server)