Question about magic command

Hi,

I am still a newbie dev, My question is there a way to remove the default output of streamlit?
what I mean is I use st.input command and every time I run it, streamlit provides a default value as the output even though i haven’t put anything as input I tried to configure it and change the magic to false in the configuration setting of streamlit but still the same.

Hi @players_hub
Could you share your code snippet or a link to your GitHub repo.

I created basic code to show what I am asking

code:
import streamlit as st

first_val = st.number_input(“Enter number:”)
second_val = st.number_input(“Enter second number”)
add_val = first_val + second_val
st.write(add_val)

output

if your going to check the image above, I put 3 as an input then streamlit show it right away . What I want to happen is streamlit show an output after calculation. I guess it got something to do with the magic command? i try to turn it off but its still the same so I dont have an dea

Hi,

You can embed your code inside st.form then use conditionals to display the sum value after the submit button is clicked.

Here’s a revised version of this:

with st.form('my_form'):
  first_value = st.number_input('Enter number:')
  second_value = st.number_input('Enter second number:')

  submitted = st.form_submit_button('Submit')
  if submitted:
      add_value = first_value + second_value
      #st.write(add_value)

if submitted:
  st.write(add_value)

Now, the output will only be shown after the submit button is clicked.

I’ve created a GitHub repo here st-form-example/streamlit_app.py at master · dataprofessor/st-form-example · GitHub

And a demo app of this here https://dataprofessor-st-form-example-streamlit-app-rz5jl9.streamlitapp.com/

Hope this helps :blush: