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"),
    "You entered:",
    ui.output_text_verbatim("text"),  
)

def server(input, output, session):
    @render.text  
    def text():
        return input.Text()

app = App(app_ui, server)
from shiny import render
from shiny.express import input, ui

ui.input_text("Text", "Enter text", "Hello Shiny")
"You entered:"

@render.text  
def text():
    return input.Text()
from shiny import App, render, ui

app_ui = ui.page_fluid(
    ui.input_text("Text", "Enter text", "Hello Shiny"),
    "You entered:",
    ui.output_text_verbatim("text"),  
)

def server(input, output, session):
    @render.text  
    def text():
        return input.Text()

app = App(app_ui, server)
No matching items

Relevant Functions

No matching items

Details

Text displays a character string as normal text.

To make reactive text, follow three steps:

  1. Call ui.output_text() in the UI of your app to create a div in which to display the text. Where you call this function within the UI functions will determine where the text will appear within the layout of the app. Set the id argument of ui.output_text() to a unique value.

  2. Within the server function, define a new function whose name matches the id used above. The function should return the text to display. Shiny will rerun this function whenever it needs to build or update the output that has the matching id.

  3. Decorate the function with @render.text

See Verbatim Text to display string values as they would appear in a computer console, in monospaced font on a shaded background.

Variations

Inline text

Set inline=True within ui.output_text() to have text appear inline with the text that preceeds it.

#| standalone: true
#| components: [viewer]
#| viewerHeight: 300

from shiny import App, render, ui

app_ui = ui.page_fluid(
    ui.input_text("Text", "Enter text", "Hello Shiny"),
    "You entered: ",
    ui.output_text("text", inline=True),  
)

def server(input, output, session):
    @render.text
    def text():
        return input.Text()

app = App(app_ui, server)
from shiny import render
from shiny.express import input, ui

ui.input_text("Text", "Enter text", "Hello Shiny")
"You entered:"

@render.text(inline=True)  
def text():
    return input.Text()
from shiny import App, render, ui

app_ui = ui.page_fluid(
    ui.input_text("Text", "Enter text", "Hello Shiny"),
    "You entered: ",
    ui.output_text("text", inline=True),  
)

def server(input, output, session):
    @render.text
    def text():
        return input.Text()

app = App(app_ui, server)
No matching items