Input with type number returning unicode after first value change
See original GitHub issueHi,
i stumbled across a problem when i wanted to use numeric input to change something in my dash app. It seems that for an dcc.Input of type number the value that is handed to the callback function is not a float but a unicode string.
The following code should clarify the problem as soon as you change a value in the browser:
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
app = dash.Dash()
app.layout = html.Div(children=[
html.H1(children='Hello Dash'),
dcc.Input(id='input_1', value=0.7, type="number"),
dcc.Input(id='input_2', value=0.7, type="number"),
html.Div(id='typeof_1'),
html.Div(id='typeof_2'),
html.Div(id='display_sum'),
]
)
@app.callback(
Output('typeof_1', 'children'),
[Input('input_1', 'value')]
)
def update_output_div(input_value1):
return 'type of input 1"{}"'.format(type(input_value1))
@app.callback(
Output('typeof_2', 'children'),
[Input('input_2', 'value')]
)
def update_output_div2(input_value2):
return 'type of input 2"{}"'.format(type(input_value2))
@app.callback(
Output('display_sum', 'children'),
[Input('input_1', 'value'),
Input('input_2', 'value'),]
)
def update_output_div3(input_value1, input_value2):
return 'sum "{}"'.format(input_value1+input_value2)
if __name__ == '__main__':
app.run_server(debug=True)
I guess the problem is that the Input is just always treated as a string no matter what type you choose. Is this something i have to live with or would you consider this a bug that should be fixed?
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
<input type="number"> - HTML: HyperText Markup Language
A Boolean attribute which, if present, means this field cannot be edited by the user. Its value can, however, still be changed by...
Read more >HTML input type="number" still returning a string when ...
When you set input type="number" then these input field don't accept non numeric input but at the same time it doesn't make the...
Read more >Insert ASCII or Unicode character codes in Word
Press and hold the ALT key and type the character code on the numeric keypad. Change the font back to your previous font...
Read more >GREL functions - OpenRefine
Takes any value type (string, number, date, boolean, error, ... Returns the first character index of sub as it first occurs in s;...
Read more >What every JavaScript developer should know about Unicode
Escape sequences in strings are used to express code units based on code point numbers. JavaScript has 3 escape types, one which was...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I do think that the implicit type casting is confusing. The user will most likely set the
valueto a number, only to find it being returned as a string (Input(value=0.7)).That’s right - We’re just using the default behaviour right now: https://github.com/plotly/dash-core-components/blob/master/src/components/Input.react.js#L28-L43
Fixing this wouldn’t be too tough, I’m in favor of it 👍
Cool! Thanks @chriddyp