@LucaR wrote:
Hello Plotly community and thanks for the amazing product, I am enjoying Dash a lot! Anyway I am not an experienced programmer and I apologize in advance if I am asking something stupid.
My issue is this:
I have 3 sql tables I would like to visualize with a DataTable, and I would like to be able to switch between these 3 via a RadioItems object.
What I wrote up to know looks like this:
(inspirated by User input that updates an SQL Query)app = dash.Dash(__name__) server = app.server def create_table(sql): conn = sqlite3.connect("/home/luca/fedigraph.sqlite3") df = pd.read_sql_query(sql, conn) conn.close() return html.Div(id='table_div', children=dash_table.DataTable( id='table', columns=[{"name": i, "id": i} for i in df.columns], data=df.to_dict('records'), )) app.layout = html.Div([html.Label('Federated Platforms'), dcc.RadioItems( id='radio', options=[ {'label': 'PeerTube', 'value': 'peertube'}, {'label': 'Friendica', 'value': 'friendica'}, {'label': 'Pleroma', 'value': 'pleroma'} ], value = 'peertube', ), html.Div(id='table_div') ]) @app.callback( Output(component_id='table_div', component_property='children'), [Input(component_id='radio', component_property='value')] ) def run_query(value): sql = "select count(*) from " + value + "_instances where timestamp > '2020-01-22 00:00:00'" return create_table(sql) if __name__ == '__main__': app.run_server(debug=True)
However, this ends up in an infinite loop and I can not figure out why. Any information or help would be extremely appreciated.
Thanks a lot.
Luca
Posts: 5
Participants: 2