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

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

1 Like

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

2 Likes