Template request | Bug report | Generate Data Product
Tags: #dash #html #conditional #formatting #element #plotly
Author: Florent Ravenel
Description: This notebook will show how to create conditional formatting of an HTML element using Dash.
References:
- https://community.plotly.com/t/conditional-formatting-of-an-html-element/60230/2
- https://dash.plotly.com/
import os
try:
import dash
except:
!pip install dash --user
import dash
try:
import dash_bootstrap_components as dbc
except:
!pip install dash_bootstrap_components --user
import dash_bootstrap_components as dbc
from dash import html, dcc, Output, Input, State
DASH_PORT
: specify a port number for Dash
DASH_PORT = 8050
app = dash.Dash(
requests_pathname_prefix=f'/user/{os.environ.get("JUPYTERHUB_USER")}/proxy/{DASH_PORT}/',
external_stylesheets=[dbc.themes.BOOTSTRAP],
meta_tags=[
{"name": "viewport", "content": "width=device-width, initial-scale=1.0"}
],
)
# app = dash.Dash() if you are not in Naas
app.title = "Naas"
app.layout = html.Div(
[
html.H1("Enter your color in HEX"),
dcc.Input(id="input"),
html.H4(id="heading", children="A Heading")
]
)
@app.callback(
Output("heading", "style"),
Input("input", "value")
)
def update_style(value):
return {
"color": value
}
if __name__ == "__main__":
app.run_server(proxy=f"http://127.0.0.1:{DASH_PORT}::https://app.naas.ai")