Skip to content

Instantly share code, notes, and snippets.

@dcbark01
Created April 25, 2018 19:52
Show Gist options
  • Save dcbark01/1a3116de0c785664e3df71edf3a3881f to your computer and use it in GitHub Desktop.
Save dcbark01/1a3116de0c785664e3df71edf3a3881f to your computer and use it in GitHub Desktop.
@app.callback(Output('button-query', 'disabled'),
[Input('my-datatable', 'selected_row_indices')])
def show_hide_query_button(selected_row_indices):
""" Callback enables/disables the query button depending on the number of rows selected. """
if len(selected_row_indices) == 1:
return False
else:
return True
@app.callback(Output('textbox-population', 'value'),
[Input('button-query', 'n_clicks'),
Input('my-datatable', 'selected_row_indices'),
Input('my-datatable', 'rows')])
def query_button_clicked(n_clicks, selected_row_indices, rows):
""" Callback to retrieve the state population and output to the textbox. """
if n_clicks > 0 and len(selected_row_indices) == 1:
row_idx = selected_row_indices[0]
state = rows[row_idx]['state']
population = df_st.loc[df_st['State'] == state, 'Population'].values
print(population)
value = 'Population of ' + state + ' is ' + str(population)
else:
n_clicks = 0
value = 'Select a single row to query in the datatable'
return value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment