Track & visualize user inputs to your streamlit app
Project description
streamlit-analytics
👀 Track & visualize user inputs to your streamlit app
This is a small extension for the fantastic streamlit framework. With just one line of code, it counts page views, tracks all user inputs to your streamlit widgets and visualizes the results directly in your browser. Think Google Analytics but for streamlit.
Installation
pip install git+https://github.com/jrieke/streamlit-analytics.git
Requires Python 3.6+
How to use it
import streamlit as st
import streamlit_analytics
with streamlit_analytics.track():
st.text_input("Write something")
st.button("Click me")
That's it! 🎈 All pageviews and user inputs are now tracked and counted. Of course,
you can also use any other streamlit widget
in the with
block (both from st.
and st.sidebar.
).
Note: One thing that doesn't work (yet) is tracking widgets created directly from
containers, expanders, or columns (e.g. st.beta_expander().button("foo")
). Instead,
please use a with statement, e.g. with st.beta_expander(): st.button("foo")
.
To view the results, open your app like normal and append ?analytics=on
to the URL
(e.g. http://localhost:8501/?analytics=on). The results are then shown directly below
your app (see image above).
More options
-
You can password-protect your analytics results with
streamlit_analytics.track(unsafe_password=...)
. The streamlit app will then ask you for this password. Do not choose an important password here – it is sent without encryption. -
If you don't want a huge
with
block, you can also do:import streamlit_analytics streamlit_analytics.start_tracking() # your streamlit code here streamlit_analytics.stop_tracking()
-
Experimental: You can store analytics results as a json file by passing
save_to_json="path/to/file.json"
tostreamlit_analytics.track
orstreamlit_analytics.stop_tracking
. At the moment, this may lead to problems with concurrency if many users access the site at the same time.
Next steps
PRs are welcome! If you want to work on any of these things, please open an issue to coordinate.
- enable tracking on widgets created directly from beta_container, beta_expander, beta_columns
- do not track inputs at each script execution but only when they change (probably requires storing current inputs in session state or cache and checking at each execution what changed)
- better display of results
- track results (or at least pageviews) per day/hour and show chart
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for streamlit-analytics-0.0.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ed8352756f334a58b12779b245ed29f7530cef2beaf1915969ef0b78afa2ec2 |
|
MD5 | b86fee4f4062191d148f61eb9d4d119e |
|
BLAKE2b-256 | 0394a17a2c0fdfc85dc5a4c33ed6f4f80d76a2ba29e39f5a0a5088d1c2d8b73d |
Hashes for streamlit_analytics-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | de3a91e2e647c8788714c862a358da17457f6efe227cf659e0b9866e6ece0ef6 |
|
MD5 | aba83b1269bf388cfdc4c810458ebe29 |
|
BLAKE2b-256 | 7eec2d45725eca9744109f97d967631ff5e26da0ad7c39d210eb3fd7cef3dd8e |