You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I first click the Chinese/English button to switch, the total_pageviews in the JSON file resets to 1. Later, when I click the Chinese/English button again, the total_pageviews increments by 1. How can I prevent the total_pageviews from resetting? Below is my code
# -*- coding: utf-8 -*-
import streamlit as st
import gettext
import streamlit_analytics2 as streamlit_analytics
import warnings
import json
warnings.filterwarnings("ignore")
st.set_page_config(
page_title="Hello",
page_icon="👋",
)
analytics_file = "./web_stats.json"
with streamlit_analytics.track(save_to_json=analytics_file):
with open(analytics_file, "r") as f:
analytics_data = json.load(f)
visits = analytics_data['total_pageviews']
if 'language' not in st.session_state:
st.session_state.language = 'en'
on = st.toggle("中文")
if on:
st.session_state.language = "zh"
else:
st.session_state.language = "en"
lang = gettext.translation('app', localedir='locales', languages=[st.session_state.language])
_ = lang.gettext
st.write(_('# Welcome to BioInz! 👋'))
st.markdown(
"""
{bioinz_description}.
{select_demo}.
### {our_focus}
- DNA
- RNA
- Protein
""".format(
bioinz_description = _("BioInz is an bioinformatics hubs"),
select_demo = _("**👈 Select a demo from the sidebar** to see some examples"),
our_focus = _("Our focus"),
)
)
st.sidebar.write("Select ......")
st.sidebar.write(f"Page views: {visits}")
The text was updated successfully, but these errors were encountered:
Hi! I think this is unfortunately a feature of SA2 as it will add +1 to a widget count upon each widget use and the way that streamlit operates is that it runs the script on every run and the first run initializes the counter at 1
I think a few months ago we used to minus 1 from the initial counter to account for that but I recall it getting changed for some reason
Let me know if that works for you. I had to fight with the code a little as I dont have the translation file but I got it to work for me or as I think you expect it to work
When I first click the Chinese/English button to switch, the total_pageviews in the JSON file resets to 1. Later, when I click the Chinese/English button again, the total_pageviews increments by 1. How can I prevent the total_pageviews from resetting? Below is my code
The text was updated successfully, but these errors were encountered: