Text Box

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

## file: app.py
from shiny import ui, render, App

app_ui = ui.page_fluid(
    ui.input_text("text", "", "Enter text...").add_class("pt-5 mx-auto text-center"),
    ui.output_text_verbatim("value"),
    {"class": "vh-100 justify-content-center align-items-center px-5"},
).add_class("my-auto text-center")

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

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

ui.input_text("text", "Text input", "Enter text...")  

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

app_ui = ui.page_fluid(
    ui.input_text("text", "Text input", "Enter text..."),  
    ui.output_text_verbatim("value"),
)

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

app = App(app_ui, server)
No matching items

Relevant Functions

  • ui.input_text
    ui.input_text(id, label, value='', *, width=None, placeholder=None, autocomplete='off', spellcheck=None)

No matching items

Details

Create input control for entry of text values.

To add a text box to your app:

  1. Add ui.input_text() to the UI of your app to create a text box. Where you call this function will determine where the text box will appear within the app’s layout.

  2. Specify the id and label parameters of ui.input_text_area() to define the identifier and label of the text box.

  3. By default, the value parameter, which defines the text box’s initial value, is the empty string (''). Provide a different string to value to change the initial text.

The value of an input component is accessible as a reactive value within the server() function. To access the value of a text box:

  1. Use input.<text_id>() (e.g., input.text()) to access the value of the text box. The server value of a text box is a string containing the current text input.

See also: Text Area