âHello everyone, Iâm getting started with Streamlit and Iâm facing a difficulty. In my form, I have a field labeled âIDâ that will receive the code I want to query, and a query button. Upon clicking this button, it will return some information about this ID.
Thereâs another âValueâ field that will receive the value to be altered. However, when I enter the ID and click on âQueryâ, it returns the desired values, but when I input a value in the âValueâ field, the previously returned information gets cleared.
How can I solve this issue?â
import mysql.connector
import json
import streamlit as st
import pandas as pd
import numpy as np
import time
import locale
import datetime
from decimal import Decimal
from streamlit_folium import st_folium
from databasecm2 import DatabaseHandler
def version_data():
config = db_handler.load_config()
version=config['version']
date_version=config['date_v']
return version, date_version
def show_negotiation():
#st.write(negotiation_result)
with st.container():
col1, col2, col3 = st.columns(3)
with col1:
if negotiation_result[0][1] is not None:
st.text(fâData criação: {negotiation_result[0][1].strftime(â%d/%m/%Y %H:%Mâ)}â)
else:
st.text(fâData criação: Nuloâ)
with col2:
if negotiation_result[0][2] is not None:
st.text(fâData atualização: {negotiation_result[0][2].strftime(â%d/%m/%Y %H:%Mâ)}â)
else:
st.text(fâData atualização: Nuloâ)
with col3:
if negotiation_result[0][3] is not None:
st.text(fâData exclusĂŁo: {negotiation_result[0][3].strftime(â%d/%m/%Y %H:%Mâ)}â)
else:
st.text(fâData exclusĂŁo: Nuloâ)
with st.container():
col1, col2, col3 = st.columns(3)
with col1:
if negotiation_result[0][13] is not None:
valor_decimal = Decimal(negotiation_result[0][13])
valor_formatado = format(valor_decimal, '.2f')
valor_formatado = valor_formatado.replace('.', '@').replace(',', '.').replace('@', ',')
st.text(f'Aluguel: {valor_formatado}')
else:
st.text(f'Aluguel: Nulo')
if name == âmainâ:
st.set_page_config(
page_title=âData Correction db LocKâ,
page_icon=ââ,
layout=âwideâ,
initial_sidebar_state=âexpandedâ,
menu_items={
âGet Helpâ: âhttps://www.lock-datacorrection.com/helpâ,
âReport a bugâ: âhttps://www.lock-datacorrection.com/bugâ,
âAboutâ: â# Data Correction db LocKâ
}
)
with open('style.css') as f:
st.markdown(f'<style>{f.read()}</style>', unsafe_allow_html=True)
# Instância da classe DatabaseHandler
db_handler = DatabaseHandler()
# Declara variaveis
global id_neg
btn_callnegotiation_press = True
btn_run_press = True
fvalue_to_be_changed = 0
locale.setlocale(locale.LC_ALL, 'pt_BR.UTF-8')
data_version_app = version_data()
st.title('Loc:orange[K] _Data_ _Correction_ ')
st.subheader(':white[Correção nos valores de aluguel dos imóveis]')
st.text(f'VersĂŁo {data_version_app[0]} {data_version_app[1]}')
with st.container():
col1, col2, col3 = st.columns([3, 1, 1])
with col1:
id_neg = st.text_input('ID',
placeholder='Digite o ID da negociação'
)
with col2:
value_to_be_changed = st.text_input('Valor',
placeholder='Novo valor do aluguel',
value='0'
)
btn_callnegotiation = st.button('Consulta')
# Mostra dados da negociação
if btn_callnegotiation:
# Inicialize a variĂĄvel `id_neg` no estado da sessĂŁo.
id_neg = st.session_state.get('id_neg', None)
negotiation_result = db_handler.load_negotiation(id_neg)
show_negotiation()
btn_callnegotiation_press = False
# Atualiza a variĂĄvel de estado de sessĂŁo `id_neg` com o novo valor.
st.session_state['id_neg'] = id_neg
if value_to_be_changed != '':
value_to_be_changed = value_to_be_changed.replace(',', '.')
fvalue_to_be_changed = float(value_to_be_changed)
if fvalue_to_be_changed != 0:
btn_run_press = False
btn_run = st.button('Executar',
disabled=btn_run_press)
if btn_run:
with st.spinner(text='Aguarde...'):
time.sleep(2)
#codigo a ser implemented