Code was working with one callback function, but when i added a second callback(change title color feature) everything stopped working and i was given a blank canvas. I would like to be able to see the bar chart, with live adjutable size graph(first callback) and manually adjusting title color(second title) PLEASE HELP, THANK YOU IN ADVANCE! :>
from dash import Dash, dcc, html, Input, Output
import plotly.express as px
from jupyter_dash import JupyterDash
import dash_daq as daq
app = JupyterDash(__name__)
colors = {
'background': '#111111',
'text': '#7FDBFF'
}
picker_style = {'float': 'left', 'margin': 'auto'}
app.layout = html.Div([
html.H1(
children='Hello Dash',
style={
'textAlign': 'center',
'color': colors['text']
}
),
html.P('Live adjustable graph-size(using Dash python)', style={'textAlign': 'center','color': colors['text']}),
html.P('Please manually Change figure width of your choice(+-200px):', style={'textAlign': 'center','color': colors['text']}),
# html.P("Change figure width:", style={'color': colors['text']}),
# dcc.Slider(id='slider', min=500, max=1900, step=200, value=1700,
# marks={x: str(x) for x in [500, 700,900,1100,1300,1500,1700, 1900]},updatemode='drag',tooltip={"placement": "bottom", "always_visible": True}),
dcc.Slider(id='slider', min=500, max=1200, step=100, value=1100,
marks={x: str(x) for x in [500,600,700,800,900,1000,1100,1200]},updatemode='drag',tooltip={"placement": "bottom", "always_visible": True}),
dcc.Graph(id="graph"),
daq.ColorPicker(
id='font', label='Font Color', size=150,
style=picker_style, value=dict(hex='#119DFF')),
daq.ColorPicker(
id='title', label='Title Color', size=150,
style=picker_style, value=dict(hex='#F71016')),
])
@app.callback(
Output("graph", "figure"),
Input('slider', 'value'))
# def display_value(width):
# return 'Width Value: {}'.format(width)
def resize_figure(width):
fig = go.Figure(data=[
go.Bar(name='Monthly Concession Passes',
x=concession["cardholders"],
y=concession["train_price"],
text = concession["train_price"]),
go.Bar(name='Average Fees using Card',
x=concession["cardholders"],
y = concession["MRT Fees"],
text = round(concession["Average Card Fees"],1)),
go.Bar(name='Single Trip Fees(cash)',
x=concession["cardholders"],
y=concession["Single Trip Fees(cash)"],
text = round(concession["Single Trip Fees(cash)"],1))
])
fig.update_layout(
barmode='group',
template="plotly_dark",
paper_bgcolor=colors['background'],
font_color=colors['text'],
title_text=
'Average Monthly Expenditure comparing Concession Passes, Card and Cash for buses',
title_x=0.5,
yaxis={
'title': 'Fees ($)',
# 'rangemode': 'tozero',
'ticks': 'outside'
})
fig.update_layout(width=int(width))
return fig
# @app.callback(
# Output("graph", 'figure'),
# Input("font", 'value'),
# Input("title", 'value')
# )
# def update_bar_chart(font_color, title_color):
# fig = go.Figure(data=[
# go.Bar(name='Monthly Concession Passes',
# x=concession["cardholders"],
# y=concession["train_price"],
# text = concession["train_price"]),
# go.Bar(name='Average Fees using Card',
# x=concession["cardholders"],
# y = concession["MRT Fees"],
# text = round(concession["Average Card Fees"],1)),
# go.Bar(name='Single Trip Fees(cash)',
# x=concession["cardholders"],
# y=concession["Single Trip Fees(cash)"],
# text = round(concession["Single Trip Fees(cash)"],1))
# ])
# fig.update_layout(
# font_color=font_color['hex'],
# title_font_color=title_color['hex'])
# return fig
#app.run_server(mode="inline")
this is data in dictionary:
{'cardholders': {0: 'Primary Student',
1: 'Secondary Student',
2: 'Polytechnic Student',
3: 'University Student',
4: 'Full-time National Serviceman',
5: 'Senior Citizen',
6: 'Adult (Monthly Travel Pass)'},
'bus_price': {0: 24.0, 1: 29.0, 2: 29.0, 3: 55.5, 4: 55.5, 5: 64.0, 6: 128.0},
'train_price': {0: 21.0,
1: 26.5,
2: 26.5,
3: 48.0,
4: 48.0,
5: 64.0,
6: 128.0},
'hybrid_price': {0: 43.5,
1: 54.0,
2: 54.0,
3: 90.5,
4: 90.5,
5: 64.0,
6: 128.0},
'Average Card Fees': {0: 8.149223099487395,
1: 8.149223099487395,
2: 8.149223099487395,
3: 8.149223099487395,
4: 20.208239081660064,
5: 11.538449007368001,
6: 20.208239081660064},
'Average Cash Fees': {0: 17.756768358801253,
1: 17.756768358801253,
2: 17.756768358801253,
3: 17.756768358801253,
4: 30.431152919426268,
5: 22.514797400960248,
6: 30.431152919426268},
'Single Trip Fees(cash)': {0: 69.0,
1: 69.0,
2: 69.0,
3: 69.0,
4: 69.0,
5: 69.0,
6: 69.0},
'MRT Fees': {0: 12.0, 1: 12.0, 2: 12.0, 3: 12.0, 4: 40.5, 5: 20.7, 6: 40.5}}