johnh
October 15, 2023, 5:42pm
1
I know I am being dumb here⦠If I use a Slider from PlutoUI I cannot get it to work with Unitful.jl types.
@bind mass Slider(1u"kg":100u"kg", show_value=true)
DimensionError: kg and 1 are not dimensionally compatible.
uconvert (::Unitful.FreeUnits{(kg,), π, nothing}, ::Int64) @conversion.jl:80
(::Colon)(::Unitful.Quantity{Int64, π, Unitful.FreeUnits{(kg,), π, nothing}}, ::Unitful.Quantity{Int64, π, Unitful.FreeUnits{(kg,), π, nothing}}) @range.jl:134
macro expansion @Local: 2277 [inlined]
top-level scope @Local: 1
That specific error is coming from 1u"kg":100u"kg"
. In constructing the range from the colon syntax thereβs an implicit step size of 1 (dimensionless) that itβs trying to materialize. Instead, you could try constructing the range object without the :
syntax:
julia> range(; start = 1u"kg", stop = 100u"kg", step = 1u"kg")
(1:100) kg
johnh
October 15, 2023, 6:33pm
3
Thankyou! I did not realise a step was involved.
This also works:
@bind mass Slider(1u"kg":1u"kg":100u"kg", show_value=true)
Dan
October 15, 2023, 7:12pm
4
Another way to write this:
julia> (1:100).*u"kg"
(1:100) kg
2 Likes