St.number_input formatter displaying blank input box

Hello!
Iā€™m trying to use number_input to display a parameter with three decimals, like so:

prior_variance = st.sidebar.number_input(
label=ā€œPrior Varianceā€,
min_value=0.00,
value=0.027,
step=0.01,
format="{:,.3f}",
)

If you pop in the following, you see the value ā€œtakesā€ but the input box is empty:

st.sidebar.markdown(str(prior_variance))

I fully admit that I may be doing something wrong with the python formatting string, but if so itā€™s not clear why the input box would be empty rather than streamlit throwing an error. Any help/insight would be appreciated!

Adam

NB Iā€™m on st version 0.51.0

1 Like

Hey @adamgoldfarb, thanks for the heads up!

To get the result youā€™re looking for, use format="%.3f". Our documentation is wrong; it claims to support Python-style format strings, but in fact it just supports printf-style strings. Iā€™ve opened a PR against that here: https://github.com/streamlit/streamlit/pull/799

Another issue is that, yeah - we definitely should be detecting bad format strings on the Python side, and show a warning. Iā€™ve opened a bug about that here: https://github.com/streamlit/streamlit/issues/800

2 Likes

Thanks @tim! I see youā€™re busy on that pull-- very much appreciate the prompt response. Thanks as always for the good work you and the team are doing.

Adam

3 Likes