Currently I have a database connected to dash. A query is run, put into a dataframe and put into my graphs. i need the graphs to be able to run a different query for different graphs. Right now I am just updating variables that formats the string that the query is contained in.
What is the best way for the user to update the query? I was trying a radio button but it seems like the output of that radio button needs to be returned somewhere inside the layout. Is there a way to have the radio button’s ‘value’ update a variable so it will insert that value into the query and run again?
What would a callback look like for something like this?
I am posting some stripped down version of my code without any callback at the bottom. Does anyone have an idea of the best way to do something like this in the most “DRY” way and least taxing?
Thanks in advance!!
server = 'server'
database = 'database'
username = 'user'
password = 'password'
conn = pyodbc.connect('DRIVER={ODBC Driver 13 for SQL Server};SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+ password)
cursor = conn.cursor()
format_select = 'format1'
table_select = 'table1'
sql = '''
SELECT {} FROM {}
'''.format(format_select, table_select)
df = pandas.io.sql.read_sql(sql, conn)
conn.close()
status_tracker = df.Digit_Status
Counter(status_tracker)
app = dash.Dash()
app.layout=html.Div([
dcc.Checklist(
id = 'checklist',
options=[
{'label': 'format1', 'value': 'format1'},
{'label': 'format2', 'value': 'format2'},
{'label': 'format3', 'value': 'format3'}
],
values=['format1']
),
dcc.Graph(
id='Status Tracker K7',
figure={
'data': [
{'x': Counter(status_tracker).keys(),
'y': Counter(status_tracker).values(),
'type': 'bar',
'width': .05},
],
'layout': {
'title': 'Status Tracker K7',
'width': '50%',
}},
style={'border': '5px solid maroon',
'margin': '30px',
'width': '700px',
'float': 'left'}
)
)),
])
if __name__ == '__main__':
app.run_server(debug=True)