How to disable the +/- function of number_input?

my app:
my repo: Github- streamlit/

In the model of my app, user could input userID and the app will generate recommendations for the userID.

However, if I click the “+” sign very quickly, it will cause the app to crash.

Is there any way that I can disable the +/- sign function of nuber_input?

1 Like

Hi @jamie613

If you do not need the +/- signs, why not go with the st.text_input() widget?

I need the input to be integer within a specific range.

But I guess using st.text_input and then check the input is a way out.

Yep, definitely.

You can set up something along those lines:

import streamlit as st

user_input = st.text_input("Enter a userID:")

# Check if user_input is an integer and not a string
if user_input.isdigit():
    user_id = int(user_input)
    st.write(f"Valid userID: {user_id}")
    st.write("Please enter a valid integer.")

Happy Streamlit’ing! :balloon:

Thank you.

Do you know why click the +/- sign fast cause the app to crash?

I’m not sure. Can you send us a quick Gif showcasing the issue, please?


It seems like I somehow resolve the problem, though I don’t know which steps work the magic. Now I can click “+” fast and up to 100 times and it won’t crash.

Thank you for your help!

1 Like

If you don’t like the +/- feature you can hide the buttons globally using css:

       "<style>" +
        ".element-container button.step-up { display: none; } " +
        ".element-container button.step-down  { display: none; } " +
        ".element-container div[data-baseweb] { border-radius: 4px; } "

I had the same problem and I preferred to turn +/- off more than risking crashes.
I feel like the crash happens because streamlit performs a rerun every time you hit +/- buttons.

This is ok even if the code takes a long time to run, but…

if you press +/- buttons 100 times I suppose streamlit tries to perform 100 reruns at the same time, instead of running only the last instance.

If you need to disable +/- not globally, but only for some field(s), this will help you a lot.
It allows you to apply html ids to single widgets, so you can target only those using css.

1 Like

I’ve tried your code and also the code in this post:

Nothing works. I’m not familiar with CSS, and will keep look in to it.

Thanks for pointing out the direction!

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