Text
Adds a text widget. It can be a text field (rows=1
) or text area (rows>1
).
import mercury as mr
# add text widget
name = mr.Text(value="Piotr", label="What is your name?", rows=1)
# use widget value in the code
print(f"Hello {name.value}!")
Running example with Mercury:
Parameters
- value (string)- the initial value of the text widget.
- label (string)- the label that will appear near the text widget.
- rows (integer)- number of rows in the text widget. Default is set to
1
. - url_key (string) - set this value if you would like to set
Text
value with URL paramters. - disabled (boolean) - disable widget in the sidebar, default is set to
False
. - hidden (boolean) - hide widget in the sidebar, default is set to
False
. - sanitize (boolean) - if set to
True
widget value is sanitized and characters like quotes and parentheses are removed, default is set toTrue
.
Share widget value in URL
Let's create the Text
widget with url_key="name"
:
import mercury as mr
# init app settings
# set show_code=True
app = mr.App(title="Text", description="Demo of Text widget", show_code=True)
# add widget
name = mr.Text(value="Piotr", label="What is your name?", rows=1, url_key="name")
# access widget value in the code
print(f"Hello {name.value}!")
You can share the widgets values with other users. Please click the Share
button in the sidebar bottom.
It will open a dialog with URL.
The URL will look like:
https://your-server-address.com/app/notebook-name?name=Piotr
Please note that ?name=Piotr
is added at the end of URL address.
Example App
Below is a screenshot with an example app. It is available at docs.runmercury.com/app/text (opens in a new tab).
Notebook's code: