Streamlit 1.20 st.number_input

In Streamlit 1.20 st.number_input is not displaying the label string even after explicitly setting label_visibility=“visible”

1 Like

Hi @bhawmik,

Thanks for posting! Can you share a code example or a screenshot to show what you’re seeing?

Variable = st.number_input(concept_str,min_value=0.0,max_value=1.0,value=Variable,key=i,label_visibility=“visible”)

Only the number input box is displayed. Label is not displayed.
For now I used a workaround my printing the label before the input box, and setting the number_input to collapsed.

To show you a screen shot I need to revert back. Can do only if you really need it.

Yes, that would be great for troubleshooting. I ran this on my end and it’s working;

import streamlit as st

number = st.number_input(label='Insert a number', label_visibility="visible")
st.write('The current number is ', number)

Screenshot 2023-03-28 at 2.44.02 PM

This is with collapsed:

import streamlit as st

number = st.number_input(label='Insert a number', label_visibility="collapsed")
st.write('The current number is ', number)

Screenshot 2023-03-28 at 2.45.01 PM

Attached is the screen shot.

st.session_state.concepts_df.loc[i, ‘Weight’] = st.number_input(label=concept_str,min_value=0.0,max_value=1.0,value=st.session_state.concepts_df.loc[i, ‘Weight’],key=i,label_visibility=“visible”)

1 Like

It used to work fine in earlier versions.
I am running on MacOs.

1 Like

So if you revert to an older version it works? Are you currently using v1.20?

Ran this example on MacOS:

import streamlit as st
import pandas as pd

st.title('Change weight as per relative importance')
# Sample DF with concepts and their corresponding weights
concepts_df = pd.DataFrame({
    'Concept': ['Concept A', 'Concept B', 'Concept C', 'Concept D'],
    'Weight': [0.35, 0.09, 0.09, 0.04]

# Initialize session state
if 'concepts_df' not in st.session_state:
    st.session_state.concepts_df = concepts_df

# Display and update the weights for each concept 
for i, concept_str in enumerate(st.session_state.concepts_df['Concept']):   
  st.session_state.concepts_df.loc[i, 'Weight'] = st.number_input(
      value=st.session_state.concepts_df.loc[i, 'Weight'],


Are you okay with sharing a screen recording or your full code?

Looks like exactly the code I have. Unfortunately I cannot share the full code. But here is the relevant segment.

st.subheader("Change weight as per relative importance." )
for i in range(st.session_state.concepts_df.shape[0]):
               concept_str = ", ".join(st.session_state.concepts_df.loc[i,'Concept'])
               concept_str =str(i)+". "+concept_str
                weight_str = str(np.round(st.session_state.concepts_df.loc[i, 'Weight'],3))
               st.session_state.concepts_df.loc[i, 'Weight'] st.number_input(concept_str,min_value=0.0,max_value=1.0,value=st.session_state.concepts_df.loc[i, 'Weight'],key=i)

Can you try running the example I gave you above on a separate file to see if it works? Also, is the app deployed to cloud or are you working locally?

Your sample code works fine.
I am running my code locally. NOt deployed to the cloud yet.

I tried plugging your code in my app. It doesn’t work then.
Something is turning off the “visibility” flag.

Here is a minimal example:

st.text_input(label="1. xx")

I guess the label is being parsed as a numbered list item and that fails when rendered as a widget label.

Some alternatives that do work:

st.text_input(label="1. xx")
st.text_input(label="1 . xx")
st.text_input(label="1: xx")
st.text_input(label="`1. `")

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.