Question about magic command


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

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


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


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

if submitted:

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

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

And a demo app of this here

Hope this helps :blush:

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