Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/444B/streamlit-analytics2 i…
Browse files Browse the repository at this point in the history
…nto test/bug-squasher-and-formatting
  • Loading branch information
444B committed Mar 10, 2024
2 parents 7ddc089 + 81930f6 commit b4dbae3
Show file tree
Hide file tree
Showing 8 changed files with 205 additions and 163 deletions.
26 changes: 12 additions & 14 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ about: Create a report to help us improve
title: "[BUG] "
labels: bug
assignees: '444B'

---

**Describe the bug**
A clear and concise description of what the bug is.
-

**Expected behavior**
A clear and concise description of what you expected to happen.
-

**To Reproduce**
Steps to reproduce the behavior:
Expand All @@ -17,22 +21,16 @@ Steps to reproduce the behavior:
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.
**Software Vesions**
Please fill in the relevant field:
- streamlit_analytics2 :
- streamlit :
- Python3 :

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]
-

**Additional context**
Add any other context about the problem here.
-
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ verify_ssl = true
name = "pypi"

[packages]
streamlit = ">=1.30"
streamlit = ">=1.31"
altair = "*"
pandas = "*"
google-cloud-firestore = "*"
Expand Down
241 changes: 104 additions & 137 deletions Pipfile.lock

Large diffs are not rendered by default.

23 changes: 17 additions & 6 deletions examples/minimal.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
import platform
import sys
import os

# Get the directory of the current script
current_script_path = os.path.dirname(os.path.abspath(__file__))

# Construct the path to the 'src' directory
src_directory_path = os.path.join(current_script_path, '..', 'src')

# Add the 'src' directory to sys.path at the first position
sys.path.insert(0, src_directory_path)

import streamlit as st
import streamlit_analytics2 as streamlit_analytics

Expand All @@ -19,9 +31,8 @@
st.text_input("Write your name")
st.selectbox("Select your favorite", ["cat", "dog", "flower"])
st.button("Click me")


st.markdown("---")
st.write(streamlit_analytics.counts)
st.markdown("---")

prompt = st.chat_input("Send a prompt to the bot")
if prompt:
st.write(f"User has sent the following prompt: {prompt}")

st.title("A [link]()")
3 changes: 3 additions & 0 deletions examples/pages/all-widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
st.time_input("time_input")
st.file_uploader("file_uploader")
st.color_picker("color_picker")
prompt = st.chat_input("Send a prompt to the bot")
if prompt:
st.write(f"User has sent the following prompt: {prompt}")

st.sidebar.checkbox("sidebar_checkbox")
st.sidebar.button("sidebar_button")
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "streamlit_analytics2"
version = "0.5.3"
version = "0.6.1"
description = "Track & visualize user interactions with your streamlit app."
authors = [{ name = "444B", email = "[email protected]" }]
license = { file = "LICENSE" }
Expand All @@ -26,7 +26,7 @@ classifiers = [
]
requires-python = ">=3.8"
dependencies = [
"streamlit >= 1.30.0",
"streamlit >= 1.31.0",
"pandas",
"altair",
"google-cloud-firestore"
Expand Down
4 changes: 1 addition & 3 deletions src/streamlit_analytics2/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
from .main import counts, start_tracking, stop_tracking, track

__version__ = "0.6.1"
from .main import counts, start_tracking, stop_tracking, track
65 changes: 65 additions & 0 deletions src/streamlit_analytics2/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ def reset_counts():
_orig_time_input = st.time_input
_orig_file_uploader = st.file_uploader
_orig_color_picker = st.color_picker
# new elements, testing
# _orig_download_button = st.download_button
# _orig_link_button = st.link_button
# _orig_page_link = st.page_link
# _orig_toggle = st.toggle
# _orig_camera_input = st.camera_input
_orig_chat_input = st.chat_input

_orig_sidebar_button = st.sidebar.button
_orig_sidebar_checkbox = st.sidebar.checkbox
Expand All @@ -64,6 +71,13 @@ def reset_counts():
_orig_sidebar_time_input = st.sidebar.time_input
_orig_sidebar_file_uploader = st.sidebar.file_uploader
_orig_sidebar_color_picker = st.sidebar.color_picker
# new elements, testing
# _orig_sidebar_download_button = st.sidebar.download_button
# _orig_sidebar_link_button = st.sidebar.link_button
# _orig_sidebar_page_link = st.sidebar.page_link
# _orig_sidebar_toggle = st.sidebar.toggle
# _orig_sidebar_camera_input = st.sidebar.camera_input




Expand Down Expand Up @@ -240,6 +254,30 @@ def new_func(label, *args, **kwargs):

return new_func

def _wrap_chat_input(func):
"""
Wrap a streamlit function that returns a single value (str/int/float/datetime/...),
e.g. st.slider, st.text_input, st.number_input, st.text_area, st.date_input,
st.time_input, st.color_picker.
"""

def new_func(placeholder, *args, **kwargs):
value = func(placeholder, *args, **kwargs)
if placeholder not in counts["widgets"]:
counts["widgets"][placeholder] = {}

formatted_value = str(value)

if formatted_value not in counts["widgets"][placeholder]:
counts["widgets"][placeholder][formatted_value] = 0

if formatted_value != st.session_state.state_dict.get(placeholder):
counts["widgets"][placeholder][formatted_value] += 1
st.session_state.state_dict[placeholder] = formatted_value
return value

return new_func


def start_tracking(
verbose: bool = False,
Expand Down Expand Up @@ -305,6 +343,13 @@ def start_tracking(
st.time_input = _wrap_value(_orig_time_input)
st.file_uploader = _wrap_file_uploader(_orig_file_uploader)
st.color_picker = _wrap_value(_orig_color_picker)
# new elements, testing
# st.download_button = _wrap_value(_orig_download_button)
# st.link_button = _wrap_value(_orig_link_button)
# st.page_link = _wrap_value(_orig_page_link)
# st.toggle = _wrap_value(_orig_toggle)
# st.camera_input = _wrap_value(_orig_camera_input)
st.chat_input = _wrap_chat_input(_orig_chat_input)

st.sidebar.button = _wrap_button(_orig_sidebar_button)
st.sidebar.checkbox = _wrap_checkbox(_orig_sidebar_checkbox)
Expand All @@ -320,6 +365,13 @@ def start_tracking(
st.sidebar.time_input = _wrap_value(_orig_sidebar_time_input)
st.sidebar.file_uploader = _wrap_file_uploader(_orig_sidebar_file_uploader)
st.sidebar.color_picker = _wrap_value(_orig_sidebar_color_picker)
# new elements, testing
# st.sidebar.download_button = _wrap_value(_orig_sidebar_download_button)
# st.sidebar.link_button = _wrap_value(_orig_sidebar_link_button)
# st.sidebar.page_link = _wrap_value(_orig_sidebar_page_link)
# st.sidebar.toggle = _wrap_value(_orig_sidebar_toggle)
# st.sidebar.camera_input = _wrap_value(_orig_sidebar_camera_input)


# replacements = {
# "button": _wrap_bool,
Expand Down Expand Up @@ -378,6 +430,13 @@ def stop_tracking(
st.time_input = _orig_time_input
st.file_uploader = _orig_file_uploader
st.color_picker = _orig_color_picker
# new elements, testing
# st.download_button = _orig_download_button
# st.link_button = _orig_link_button
# st.page_link = _orig_page_link
# st.toggle = _orig_toggle
# st.camera_input = _orig_camera_input
st.chat_input = _orig_chat_input

st.sidebar.button = _orig_sidebar_button
st.sidebar.checkbox = _orig_sidebar_checkbox
Expand All @@ -393,6 +452,12 @@ def stop_tracking(
st.sidebar.time_input = _orig_sidebar_time_input
st.sidebar.file_uploader = _orig_sidebar_file_uploader
st.sidebar.color_picker = _orig_sidebar_color_picker
# new elements, testing
# st.sidebar.download_button = _orig_sidebar_download_button
# st.sidebar.link_button = _orig_sidebar_link_button
# st.sidebar.page_link = _orig_sidebar_page_link
# st.sidebar.toggle = _orig_sidebar_toggle
# st.sidebar.camera_input = _orig_sidebar_camera_input

# Save count data to firestore.
# TODO: Maybe don't save on every iteration but on regular intervals in a background
Expand Down

0 comments on commit b4dbae3

Please sign in to comment.