Update slider's marks by callback
dimitryerkin opened this issue · comments
Hello,
The following code demonstrates that there is an issue with updating the slider's marks using a callback. If you run this code and press the "Test Slider" button twice, then the marks, which are set up while creating a slider, will be erased by the callback function:
update_slider_callback_function
marks:(1 = "1", 2 = "2")
update_slider_callback_function
marks:1
The code:
`
using Dash, DashHtmlComponents, DashCoreComponents, DashTable, Printf
app = dash(; suppress_callback_exceptions=true)
app.layout = html_div() do
children=[
html_button("Test Slider", id="test"),
dcc_slider(id="range_test", min=1, max=2, marks=Dict(1 => "1", 2 => "2"))
]
end
updateSliderState =
[
State("range_test", "marks")
]
updateSliderInput =
[
Input("test", "n_clicks")
]
updateSliderOutput =
[
Output("range_test", "marks")
]
function update_slider_callback_function(
n_clicks, marksCurrent
)
println("update_slider_callback_function")
println("marks:", marksCurrent)
Dict(1 => "1", 2 => "2")
end
callback!(
update_slider_callback_function,
app,
updateSliderOutput,
updateSliderInput,
updateSliderState
)
run_server(app, "0.0.0.0", 8080)
`
I really need this feature, so what would you recommend me as a workaround?
Thanks.
The workaround is to replace Dict(1 => "1", 2 => "2")
with Dict(1 => Dict(1 => "1", 2 => "2"))
Thanks.
The workaround is to replace Dict(1 => "1", 2 => "2") with Dict(1 => Dict(1 => "1", 2 => "2"))
If you look at the code, the output in this code is an array of one element, so the callback should also return an array. That's why this workshop is needed. Or you can just make output a single value and not an array