# Slider with Unitful.jl values

**URL:** <https://discourse.julialang.org/t/slider-with-unitful-jl-values/104986>\
**Category:** Pluto\
**Created:** [October 15, 2023, 5:42pm UTC](https://discourse.julialang.org/t/slider-with-unitful-jl-values/104986 "2023-10-15T17:42:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnh/32/3615_2.png) [@johnh](https://discourse.julialang.org/u/johnh)\
**Post date:** [October 15, 2023, 5:42pm UTC](https://discourse.julialang.org/t/slider-with-unitful-jl-values/104986/1 "2023-10-15T17:42:38Z")

</div>

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.

1. **uconvert** (::Unitful.FreeUnits{(kg,), 𝐌, nothing}, ::Int64)@_conversion.jl:80_
2. (::Colon)(::Unitful.Quantity{Int64, 𝐌, Unitful.FreeUnits{(kg,), 𝐌, nothing}}, ::Unitful.Quantity{Int64, 𝐌, Unitful.FreeUnits{(kg,), 𝐌, nothing}})@_range.jl:134_
3. **macro expansion** @_[Local: 2277](http://localhost:1234/edit?id=168fdf98-6b7e-11ee-0dcc-f7eb40c90584#)_ [inlined]
4. **top-level scope** @_[Local: 1](http://localhost:1234/edit?id=168fdf98-6b7e-11ee-0dcc-f7eb40c90584#)_

---

<div class="post-metadata">

**Author:** ![sbuercklin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sbuercklin/32/15728_2.png) [@sbuercklin](https://discourse.julialang.org/u/sbuercklin)\
**Post date:** [October 15, 2023, 6:12pm UTC](https://discourse.julialang.org/t/slider-with-unitful-jl-values/104986/2 "2023-10-15T18:12:32Z")

</div>

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
julia> range(; start = 1u"kg", stop = 100u"kg", step = 1u"kg")
(1:100) kg

```

---

<div class="post-metadata">

**Author:** ![johnh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnh/32/3615_2.png) [@johnh](https://discourse.julialang.org/u/johnh)\
**Post date:** [October 15, 2023, 6:33pm UTC](https://discourse.julialang.org/t/slider-with-unitful-jl-values/104986/3 "2023-10-15T18:33:53Z")

</div>

Thankyou! I did not realise a step was involved.  
This also works:  
@bind mass Slider(1u"kg":1u"kg":100u"kg", show\_value=true)

---

<div class="post-metadata">

**Author:** ![Dan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dan/32/42581_2.png) [@Dan](https://discourse.julialang.org/u/Dan)\
**Post date:** [October 15, 2023, 7:12pm UTC](https://discourse.julialang.org/t/slider-with-unitful-jl-values/104986/4 "2023-10-15T19:12:18Z")

</div>

Another way to write this:

```julia
julia> (1:100).*u"kg"
(1:100) kg

```
