I have a dataframe with the columns
App | Week | Top Users
-------+--------+------------------------------
App 1 | Week 1 |[1st user, 2nd user, 3rd user]
that shows the top 3 users of each app per week. The Top Users cells contain a list of the top 3 users.
Now i want to build a dash Data Table that gets updated when i select the App from a dropdown list.
I am trying to make the table look like this
Week 1 | Week 2 | Week 3 | Week 4
---------+---------+------- -+----------
1st user| 1st user| 1st user| 1st user
---------+---------+------- -+----------
2nd user| 2nd user| 2nd user| 2nd user
---------+---------+------- -+----------
3rd user| 3rd user| 3rd user| 3rd user
app = dash.Dash()
top_users['Week'] = pd.DatetimeIndex(top_users['Week']).strftime("%d/%m/%Y")
app_options = []
for apps in top_users['App'].unique():
app_options.append({'label':str(apps), 'value':apps})
weeks = []
for week in top_users['Week'].unique():
weeks.append(week)
app.layout = html.Div(children=[
dash_table.DataTable(
id='top-users',
columns=[{"name": i, "id": i} for i in weeks],
fixed_rows={'headers': True}
) ,
dcc.Dropdown(id='app-picker', options=app_options),
])
@app.callback(
Output('top-users', 'data'),
Input('app-picker', 'value'))
def update_table(selected_app):
data = top_users.loc[top_users['App']==selected_app]
return data.to_dict('records')
if __name__ == '__main__':
app.run_server(host="127.0.0.1", port=8060)
The code above doesn’t show anything at all