Skip to content

Commit

Permalink
Adding missing key parameter to text_input (streamlit#571)
Browse files Browse the repository at this point in the history
* Adding key parameter to number_input

* Test

* linter
monchier authored Oct 30, 2019
1 parent e3dbeb0 commit 9caa414
Showing 3 changed files with 8 additions and 24 deletions.
10 changes: 7 additions & 3 deletions lib/streamlit/DeltaGenerator.py
Original file line number Diff line number Diff line change
@@ -2056,6 +2056,7 @@ def number_input(
value=NoValue(),
step=None,
format=None,
key=None,
):
"""Display a numeric input widget.
@@ -2079,6 +2080,11 @@ def number_input(
format : str or None
Printf/Python format string controlling how the interface should
display numbers. This does not impact the return value.
key : str
An optional string to use as the unique key for the widget.
If this is omitted, a key will be generated for the widget
based on its content. Multiple widgets of the same type may
not share the same key.
Returns
-------
@@ -2092,8 +2098,6 @@ def number_input(
>>> st.write('The current number is ', number)
"""

from streamlit.util import is_int_value

if isinstance(value, NoValue):
if min_value:
value = min_value
@@ -2179,7 +2183,7 @@ def number_input(
if format is not None:
element.number_input.format = format

ui_value = _get_widget_ui_value("number_input", element)
ui_value = _get_widget_ui_value("number_input", element, user_key=key)

return ui_value if ui_value is not None else value

21 changes: 0 additions & 21 deletions lib/streamlit/util.py
Original file line number Diff line number Diff line change
@@ -498,24 +498,3 @@ def file_is_in_folder_glob(filepath, folderpath_glob):

file_dir = os.path.dirname(filepath) + "/"
return fnmatch.fnmatch(file_dir, folderpath_glob)


def is_int_value(value):
"""Test if a given value is int
Parameters
----------
value: any
Returns
-------
bool
True if is an int, False if not
"""

try:
a = float(value)
b = int(a)
except ValueError:
return False
else:
return a == b
1 change: 1 addition & 0 deletions lib/tests/streamlit/delta_generator_test.py
Original file line number Diff line number Diff line change
@@ -224,6 +224,7 @@ def test_duplicate_widget_id_error(self):
"text_input": lambda key=None: st.text_input("", key=key),
"time_input": lambda key=None: st.time_input("", key=key),
"date_input": lambda key=None: st.date_input("", key=key),
"number_input": lambda key=None: st.number_input("", key=key),
}

# Iterate each widget type

0 comments on commit 9caa414

Please sign in to comment.