Skip to content

Commit

Permalink
fix selectbox
Browse files Browse the repository at this point in the history
  • Loading branch information
Cuttlas90 committed Jul 27, 2024
1 parent 093a9f8 commit 1acbc04
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 8 deletions.
19 changes: 16 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import streamlit as st
import altair as alt
import pandas as pd

from login import check_local_token
from pages.helper.monthly_chart import add_monthly_charts
Expand Down Expand Up @@ -46,8 +47,20 @@ def sfmono():

add_menu()
st.components.v1.html(MAIN_PAGE, height=60, scrolling=False)

name, selected_stock = add_list_selector()
if "stock_index" not in st.session_state:
st.session_state.stock_index = 0
df = pd.read_csv("data.csv").dropna()
list_of_name = df['name'].to_list()
if "stock" in st.query_params:
st.session_state.stock_index = list_of_name.index(st.query_params.stock)
name = st.sidebar.selectbox(
"لیست سهام",
options = list_of_name,
index=st.session_state.stock_index,
key="stock_slector",
disabled=True)
st.session_state.stock_index = int((df.loc[df['name'] == name].index[0]).astype(str))
selected_stock = df.iloc[df.loc[df['name'] == name].index[0]]
dollar_toggle = st.sidebar.toggle(
"نمایش به دلار",
help="با فعال کردن این گزینه تمامی مبالغ بر اساس دلار بازمحاسبه می گردد."
Expand All @@ -56,7 +69,7 @@ def sfmono():

check_local_token()
if "token" in st.session_state:
queries = Queries(name)
queries = Queries(st.session_state.stock_index)

error, stock_data = vasahm_query(queries.get_stock_data())
if error:
Expand Down
6 changes: 4 additions & 2 deletions menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ def add_list_selector():
name = st.sidebar.selectbox(
"لیست سهام",
options = list_of_name,
index=st.session_state.stock_index)
index=st.session_state.stock_index,
key="stock_slector",
disabled=True)
st.session_state.stock_index = int((df.loc[df['name'] == name].index[0]).astype(str))
selected_stock = df.iloc[df.loc[df['name'] == name].index[0]]
return name, selected_stock
return selected_stock
15 changes: 14 additions & 1 deletion pages/simple_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,20 @@
if "ver" in st.session_state:
st.sidebar.header(f'Vasahm DashBoard `{st.session_state.ver}`')

name, _ = add_list_selector()
if "stock_index" not in st.session_state:
st.session_state.stock_index = 0
df = pd.read_csv("data.csv").dropna()
list_of_name = df['name'].to_list()
if "stock" in st.query_params:
st.session_state.stock_index = list_of_name.index(st.query_params.stock)
name = st.sidebar.selectbox(
"لیست سهام",
options = list_of_name,
index=st.session_state.stock_index,
key="stock_slector",
disabled=True)
st.session_state.stock_index = int((df.loc[df['name'] == name].index[0]).astype(str))
selected_stock = df.iloc[df.loc[df['name'] == name].index[0]]

dfg = get_stock_monthly(name)

Expand Down
15 changes: 14 additions & 1 deletion pages/social_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,20 @@

add_menu()

name, _ = add_list_selector()
if "stock_index" not in st.session_state:
st.session_state.stock_index = 0
df = pd.read_csv("data.csv").dropna()
list_of_name = df['name'].to_list()
if "stock" in st.query_params:
st.session_state.stock_index = list_of_name.index(st.query_params.stock)
name = st.sidebar.selectbox(
"لیست سهام",
options = list_of_name,
index=st.session_state.stock_index,
key="stock_slector",
disabled=True)
st.session_state.stock_index = int((df.loc[df['name'] == name].index[0]).astype(str))
selected_stock = df.iloc[df.loc[df['name'] == name].index[0]]

if "ver" in st.session_state:
st.sidebar.header(f'Vasahm DashBoard `{st.session_state.ver}`')
Expand Down
15 changes: 14 additions & 1 deletion pages/technical.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,20 @@
if "ver" in st.session_state:
st.sidebar.header(f'Vasahm DashBoard `{st.session_state.ver}`')

name, _ = add_list_selector()
if "stock_index" not in st.session_state:
st.session_state.stock_index = 0
df = pd.read_csv("data.csv").dropna()
list_of_name = df['name'].to_list()
if "stock" in st.query_params:
st.session_state.stock_index = list_of_name.index(st.query_params.stock)
name = st.sidebar.selectbox(
"لیست سهام",
options = list_of_name,
index=st.session_state.stock_index,
key="stock_slector",
disabled=True)
st.session_state.stock_index = int((df.loc[df['name'] == name].index[0]).astype(str))
selected_stock = df.iloc[df.loc[df['name'] == name].index[0]]
dollar_toggle = st.sidebar.toggle(
"نمایش به دلار",
help="با فعال کردن این گزینه تمامی مبالغ بر اساس دلار بازمحاسبه می گردد."
Expand Down

0 comments on commit 1acbc04

Please sign in to comment.