'Using a slider to add rows to Ploty's Dash "dash_table"
I'm currently working on a dash_table in which I have already incorporated an add row button as well as delete. I would like the user to also be able to add rows by using a slider value. How would I be able to do that with making changes to current code?
html.Div(children=[
html.Label('# of Wells on Pad', style={'color':colors['text']}),
dcc.Slider(
id='well_slider',
min=0,
max=12,
step=1,
marks={i: f' {i}' if i == 1 else str(i) for i in range(13)},
value=0,
),
], style={'padding': 10, 'flex': 1, 'background-color':colors['background'],'margin':20})
], style={'display': 'flex', 'flex-direction': 'row',}),
# html.
html.Div(children=[
dash_table.DataTable(
id='projection_table',
columns=[{
'name': i,
'id': i,
} for i in table_outputs],
style_cell={'text-align':'center'},
data=[
{'column-{}'.format(i): (j + (i-1)*5) for i in range(1, 5)}
for j in range(5)
],
editable=True,
fill_width=True,
row_deletable=True,
export_format='xlsx',
export_headers='display',
style_table={'overflowX':'scroll'}
),
html.Button('Add Row', id='editing-rows-button', n_clicks=0, style={'margin':5}),
html.Div(id='testingSlider', style={"color":colors['text']})
],style={'margin':10})
@app.callback(
Output('projection_table', 'data'),
Input('editing-rows-button', 'n_clicks'),
State('projection_table', 'data'),
State('projection_table', 'columns')
)
def add_row(n_clicks, rows, table_outputs):
if n_clicks > 0:
rows.append({c['id']: '' for c in table_outputs})
return rows
@app.callback(
Output('testingSlider', 'children'),
Input('well_slider', 'value'),
State('projection_table', 'data'),
State('projection_table', 'columns')
)
def add_row_slider(value, rows, table_outputs):
if value > 0:
rows.append({c['id']: '' for c in table_outputs})
return rows
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
