Form/start/stop button not working

Hi,
I am new to Streamlit. Was trying it out on my local machine, but ran into problems of streamlit not rerunning as per my understanding. Any help would be much appreciated. I am using Python 3.9. Following is the test case code that I run with the command:

streamlit run testcase.py
It opens the browser fine with the required forms and buttons. First time around the “Start” button works and it starts the program. But if I do any changes to the form values, it does not take effect when I again press the “Start” button. Also, when I press the “Stop” button, the program does not stop. I rolled back the streamlit to 0.86 version from the latest one, then also it does not work. Not sure what I am missing.

Regards.

testcase.py:

from time import sleep
import streamlit as st

bell = ‘ON’

form = st.sidebar.form(key=“myform”)
stop_loss_target_total = form.number_input(“SL Target”, value=int(600))
profit_target_total = form.number_input(“Profit Target”, value=int(800))
sleep_interval = form.number_input(“Sleep Interval”, value=int(3))
start = form.form_submit_button(“Start”)
stop = st.sidebar.button(“Stop”)

def print_parameter_values():
print(f’\tSleep Interval: {sleep_interval} Secs’)
print(f’\tProfit Target (per lot): {profit_target_total}‘)
print(f’\tStop Loss (per lot): {stop_loss_target_total}‘)
print(f’\tBell: {bell}‘)
# print(f’\n’)

print(‘Waiting for connection…’)
print(“Connected…”)
if bell == ‘ON’:
print(f’Bell: {bell}')

print(start, stop)

def run_strategy():
i = 0
while True:
print(i, start, stop)
print(f’Current Parameters For The Run:‘)
print_parameter_values()
print(f’Hi2 {start}, {stop}’)
sleep(sleep_interval)
i = i+1

if start:
print(‘In start’)
print(start)
run_strategy()
if stop:
print(‘In stop’)
print(stop)
st.write(‘Exiting…’)

It is working now… no longer an issue. This can be closed. Thanks.

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