Text Box
#| '!! shinylive warning !!': |
#| shinylive does not work in self-contained HTML documents.
#| Please set `embed-resources: false` in your metadata.
#| 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)Relevant Functions
-
ui.input_text
ui.input_text(id, label, value='', *, width=None, placeholder=None, autocomplete='off', spellcheck=None)
Details
Create input control for entry of text values.
To add a text box to your app:
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.Specify the
idandlabelparameters ofui.input_text_area()to define the identifier and label of the text box.By default, the
valueparameter, which defines the text box’s initial value, is the empty string (''). Provide a different string tovalueto 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:
- 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
Variation Showcase
A live kitchen sink of all possible parameters for the Text Box in Shiny Core and Shiny Express.
![]()