I have an oddity in my code that may potentially be a bug
I have a DataFrame and two launches buttons. One makes a CheckList and the Other makes a Radio Item. They each make the same list (the column titles from the Data frame).
The Radio Item launch button works every single time (I ran it about 20 times and all was well)
The Check List launch button sometimes works. And when it doesn’t work the other launch button also stops working. However no error is returned.
By inserting a print statement returning the n-clicks value I have found that when the checklist doesn’t generate n-clicks stops increasing, however dash still registers the value.
The code is below (sorry for the length):
import dash_html_components as html
import dash_core_components as dcc
import dash
import dash_table_experiments as dte
from dash.dependencies import Input, Output, State
import pandas as pd
import numpy as np
import json
import datetime
import operator
import os
import base64
import io
af = pd.DataFrame([[1,2,3],[2,3,4],[3,4,5]],columns=["a","b","c"])
def generate_table(dataframe):
return html.Table([html.Tr([html.Th(col) for col in dataframe.columns])])
def Sumation_Data():
matrix_ad = [["Name"]]
return pd.DataFrame(matrix_ad,columns = matrix_ad.pop(0))
app = dash.Dash()
app.layout = html.Div([
html.Div([
html.Div(dte.DataTable(rows=af.to_dict('records'), id='Table of Data')),]),
html.Button(
id='Make_Graph1',
n_clicks = 0,
children='CheckList'
),
html.Div(
children =[
dcc.Checklist(
id = "Column_Names1",
values=[]
),
],
),
html.Div(id='Sumation_Data'),
html.Button(
id='Make_Graph2',
n_clicks = 0,
children='RadioItem'
),
html.Div(
children =[
dcc.RadioItems(
id = "Column_Names2",
value=""
),
],
),
]
)
@app.callback(
dash.dependencies.Output('Sumation_Data', 'children'),
[Input('Table of Data', 'rows'),
Input("Make_Graph1", "n_clicks"),
Input("Column_Names1","values")])
def Make_Histograms_Graph(af,Click,Column):
if Click < 1:
return []
else:
if Column == []:
return [{}]
else:
df = pd.DataFrame.from_dict(af)
if not df.empty:
a = Sumation_Data()
return generate_table(a)
else:
return [{}]
@app.callback(
dash.dependencies.Output("Column_Names1", 'options'),
[Input('Table of Data', 'rows'),
Input("Make_Graph1", "n_clicks")])
def Make_Column_Options1_1(af,Click):
if Click < 1:
return []
else:
df = pd.DataFrame.from_dict(af)
print(Click)
return [{'label': i, 'value': i} for i in list(df.columns.values)]
@app.callback(
dash.dependencies.Output("Column_Names2", 'options'),
[Input('Table of Data', 'rows'),
Input("Make_Graph2", "n_clicks")])
def Make_Column_Options2(af,Click):
if Click < 1:
return []
else:
df = pd.DataFrame.from_dict(af)
print(Click)
return [{'label': i, 'value': i} for i in list(df.columns.values)]
if __name__ == '__main__':
app.run_server(debug=True)
Please could someone confirm whether I have made an error or if it is a bug?