Skip to content

Instantly share code, notes, and snippets.

@dcbark01
Created April 24, 2018 20:13
Show Gist options
  • Save dcbark01/32c0a89361caa7707ec1ddd90f82d918 to your computer and use it in GitHub Desktop.
Save dcbark01/32c0a89361caa7707ec1ddd90f82d918 to your computer and use it in GitHub Desktop.
@app.callback(Output('datatable-subplots', 'figure'),
[Input('my-datatable', 'rows'),
Input('my-datatable', 'selected_row_indices')])
def update_figure(rows, selected_row_indices):
dff = pd.DataFrame(rows)
fig = plotly.tools.make_subplots(
rows=3, cols=1,
subplot_titles=('Beef', 'Pork', 'Poultry'),
shared_xaxes=True)
marker = {'color': ['#0074D9']*len(dff)}
for i in (selected_row_indices or []):
marker['color'][i] = '#FF851B'
fig.append_trace({
'x': dff['state'],
'y': dff['beef'],
'type': 'bar',
'marker': marker
}, 1, 1)
fig.append_trace({
'x': dff['state'],
'y': dff['pork'],
'type': 'bar',
'marker': marker
}, 2, 1)
fig.append_trace({
'x': dff['state'],
'y': dff['poultry'],
'type': 'bar',
'marker': marker
}, 3, 1)
fig['layout']['showlegend'] = False
fig['layout']['height'] = 1000
fig['layout']['width'] = 1200
fig['layout']['margin'] = {
'l': 40,
'r': 10,
't': 60,
'b': 200
}
return fig
app.css.append_css({
'external_url': 'https://codepen.io/chriddyp/pen/bWLwgP.css'
})
if __name__ == '__main__':
app.run_server(debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment