Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
jupyter-naas
GitHub Repository: jupyter-naas/awesome-notebooks
Path: blob/master/Dash/Dash_Create_conditional_formatting_on_HTML_element.ipynb
2973 views
Kernel: Python 3

Dash.png

Dash - Create conditional formatting on HTML element

Give Feedback | Bug report

Tags: #dash #html #conditional #formatting #element #plotly

Last update: 2023-05-24 (Created: 2023-05-24)

Description: This notebook will show how to create conditional formatting of an HTML element using Dash.

Input

Import libraries

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

Setup Variables

  • DASH_PORT: specify a port number for Dash

DASH_PORT = 8050

Model

Initialize Dash app

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

Create app layout

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 }

Output

Generate URL and show logs

if __name__ == "__main__": app.run_server(proxy=f"http://127.0.0.1:{DASH_PORT}::https://app.naas.ai")