Skip to content

Commit

Permalink
Fix bug where sliders were always returning a tuple (streamlit#1243)
Browse files Browse the repository at this point in the history
  • Loading branch information
tvst authored Aug 19, 2019
1 parent 0843078 commit a10f094
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
7 changes: 3 additions & 4 deletions lib/streamlit/DeltaGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1455,11 +1455,10 @@ def slider(self, element, ui_value, label, value=None,
# single variable
current_value = current_value[0] if single_value else current_value

if single_value:
current_value = [current_value]

element.slider.label = label
element.slider.value[:] = current_value
element.slider.value[:] = (
[current_value] if single_value
else current_value)
element.slider.min = min_value
element.slider.max = max_value
element.slider.step = step
Expand Down
18 changes: 10 additions & 8 deletions lib/tests/streamlit/slider_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,18 @@ def test_just_label(self):
self.assertEqual(c.value, [0.0])

@parameterized.expand([
(0, [0.0]),
(0.0, [0.0]),
((0, 1), [0.0, 1.0]),
([0, 1], [0.0, 1.0]),
((0.0, 1.0), [0.0, 1.0]),
([0.0, 1.0], [0.0, 1.0])
(0, [0.0], 0),
(0.0, [0.0], 0.0),
((0, 1), [0.0, 1.0], (0, 1)),
([0, 1], [0.0, 1.0], (0, 1)),
((0.0, 1.0), [0.0, 1.0], (0.0, 1.0)),
([0.0, 1.0], [0.0, 1.0], (0.0, 1.0))
])
def test_value_types(self, arg_value, proto_value):
def test_value_types(self, arg_value, proto_value, return_value):
"""Test that it supports different types of values."""
st.slider('the label', arg_value)
ret = st.slider('the label', arg_value)

self.assertEqual(ret, return_value)

c = self.get_delta_from_queue().new_element.slider
self.assertEqual(c.label, 'the label')
Expand Down

0 comments on commit a10f094

Please sign in to comment.