Cannot modify slider attributes from callback
chaseleslie opened this issue · comments
Consider the following minimal Dash.jl app consisting of a slider and a button:
using Dash, DashHtmlComponents, DashCoreComponents
app = dash()
app.layout = html_div() do
html_h1("Slider Demo"),
dcc_slider(
id="my_slider",
min=1,
max=10,
value=1,
marks=Dict(Symbol(k) => Symbol(k) for k in 1:10)
),
html_button("Change Marks", id="change_marks")
end
callback!(
app,
Output("my_slider", "min"),
Output("my_slider", "max"),
Output("my_slider", "value"),
Output("my_slider", "marks"),
Input("change_marks", "n_clicks"),
State("my_slider", "min"),
State("my_slider", "max"),
State("my_slider", "value"),
State("my_slider", "marks")
) do nClicks, sliderMin, sliderMax, sliderValue, sliderMarks
if nClicks === nothing
return (sliderMin, sliderMax, sliderValue, sliderMarks)
end
return (
1, 20, 1, Dict(Symbol(k) => Symbol(k) for k in 1:20)
)
end
run_server(app, "0.0.0.0", debug=true)
When the button is clicked, the slider min
, max
and value
should be modified by the callback. However, these attributes are not modified. Note that unlike in #45, modifying the marks
works (but only the modified marks
between the old min
and max
will be shown). This may be related to #77, which was about a ranged slider instead.
Here is a python version of the same code, that works as expected:
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output, State
app = dash.Dash(__name__)
app.layout = html.Div([
html.H1(children="Slider Demo"),
dcc.Slider(
id="my_slider",
min=1,
max=10,
value=1,
marks={k: '{}'.format(k) for k in range(1,11)}
),
html.Button("Change Marks", id="change_marks")
])
@app.callback(
Output("my_slider", "min"),
Output("my_slider", "max"),
Output("my_slider", "value"),
Output("my_slider", "marks"),
Input("change_marks", "n_clicks"),
State("my_slider", "min"),
State("my_slider", "max"),
State("my_slider", "value"),
State("my_slider", "marks")
)
def update_slider(nClicks, sliderMin, sliderMax, sliderValue, sliderMarks):
if not nClicks:
return (sliderMin, sliderMax, sliderValue, sliderMarks)
return (1, 20, 1, {k: '{}'.format(k) for k in range(1,21)})
if __name__ == '__main__':
app.run_server(debug=True)
Using Julia version 1.5.3, Dash 0.1.3, DashCoreComponents 1.12.0.
This code works in Dash 1.0.0. Maybe the problem was in the old version of the js code of DashCoreComponents
Indeed it is working as expected now.