Hello, Dash community,
I have a textbox that allows users to enter any statement. The text will be shown after triggering the confirm button. The default color is black, how can I show the text with different colors? Such as “You have entered” as blue and “Game of Thrones” as red?
For example,
to this,
import numpy as np
import pandas as pd
import dash
from dash.dependencies import Input, Output, State
import dash_html_components as html
import dash_core_components as dcc
import dash_bootstrap_components as dbc
import dash_table as dt
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__,
external_stylesheets=external_stylesheets
)
app.layout = html.Div(children=[
# Header
dbc.Row(children=[
html.H3(children=["This is my title"],
style={"text-align": "center"})
]),
# Textarea
dcc.Textarea(
id='textarea',
placeholder='Please Enter a Description...',
style={'width': '100%', 'height': 200},
),
# Button
html.Button('Confirm', id='button', n_clicks=0),
html.Br(),
html.Br(),
html.Br(),
# children
dbc.Row(children=[
dcc.Loading(
id="loading-1",
type="circle", # circle default
children=html.Div(id='output_children')
),
],
style={'width': '100%', 'padding': '5px 5px', 'display': 'inline-block'}),
])
@app.callback(
[Output(component_id='output_children', component_property='children')],
[Input(component_id='button', component_property='n_clicks'),
State(component_id='textarea', component_property='value')],
prevent_initial_call=True
)
def update_output(n_clicks, textarea):
if n_clicks > 0:
my_children = html.H5(children=['You have entered: \n{}'.format(textarea)])
return [my_children]
if __name__ == '__main__':
app.run_server(debug=False,
# host="sd-hchs-rc46.nam.nsroot.net",
port=8005)
Thx in advance!