Skip to main content

Streamlit component that allows you to get simple facts about the screen to provide custom contextual app designs

Project description

streamlit-screen-stats

Streamlit component that allows you to do get various stats for your screeen to build repsonsive apps for your users with different devices.

Installation instructions

pip install streamlit-screen-stats

Usage instructions

import streamlit as st
from st_screen_stats import ScreenData, StreamlitNativeWidgetScreen, WindowQuerySize, WindowQueryHelper

# using react component
screenD = ScreenData(setTimeout=1000)
screen_d = screenD.st_screen_data()
st.write(screen_d)

## You can now use the on_change parameter on all class methods of this package. 
def onScreenSizeChange(variable):
    ## do something when the screen size has changed.
    #example
    print(variable)
    
screen_stats_result = screenD.st_screen_data(key="screen_stats_", on_change=onScreenSizeChange("this works")) 
st.write(st.session_state["screen_stats_"]) 

# using sctreamlit native widget and some custom components
# Requirements:
#  Need to install from pypi:
#    - streamlit-browser-session-storage (pip install streamlit-browser-session-storage)
#    - streamlit-local-storage (pip install streamlit-local-storage)
screenDN = StreamlitNativeWidgetScreen(setTimeout=1000) 
screen_stats_window = screenDN.get_window_screen_stats()
st.write(screen_stats_window)

# Query window screen like you would when using CSS @media () {}
# Returns dictionary result `{'status':True}` if conditions are met else `{'status':False}` if conditions are not met.
window_width_query_raw = WindowQuerySize()
window_width_res = window_width_query_raw.mediaQuery(mediaMatchQ="(max-width: 700px)") # returns dictionary result {'status':True} if window screen width is lower than 700px else {'status':False} if window screen width is greater than 700px
st.write(window_width_res)


# Query window screen helper - simplifies the above (CSS @media () {}) method
helper_screen_stats = WindowQueryHelper()
max_width_window = helper_screen_stats.maximum_window_size(max_width=800, key="window_1")
st.write("max_width",max_width_window)
min_width_window = helper_screen_stats.minimum_window_size(min_width=800, key="window_2")
st.write("min_width",min_width_window) 

window_range = helper_screen_stats.window_range_width(min_width=1000, max_width=1100)
st.write("range", window_range) 

## You can now use the on_change parameter. 
# Example:

def onScreenSizeChange(value):

    print(value)

large_screen_size_ = helper_screen_stats.window_range_width(min_width=1000, max_width=1100, on_change=onScreenSizeChange(value) key="lg_screen")

if large_screen_size_["status"] or st.session_state["lg_screen"]["status"]:
    st.write("rest of code here")

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

streamlit_screen_stats-0.0.75.tar.gz (1.1 MB view details)

Uploaded Source

Built Distribution

streamlit_screen_stats-0.0.75-py3-none-any.whl (1.1 MB view details)

Uploaded Python 3

File details

Details for the file streamlit_screen_stats-0.0.75.tar.gz.

File metadata

File hashes

Hashes for streamlit_screen_stats-0.0.75.tar.gz
Algorithm Hash digest
SHA256 1ab5138d94c9662f097af37d7ba435c0a0bdad8ea6261fc6a87fd23f2ee7cdf5
MD5 b106ae066d2ab516916b4c972211bd00
BLAKE2b-256 af2e1ef55d7ba32f257c1a8c99e15f0b15e48cdef2c456edf3e617b6fdfd5a9b

See more details on using hashes here.

File details

Details for the file streamlit_screen_stats-0.0.75-py3-none-any.whl.

File metadata

File hashes

Hashes for streamlit_screen_stats-0.0.75-py3-none-any.whl
Algorithm Hash digest
SHA256 3f0b0df65ffeeea0ccce251bc9f043c139a222a5ae206df5eaac7f146cc18cec
MD5 c457547be37a5b05d0db9114d4d17970
BLAKE2b-256 06cb1eb90c2b3845b64ae12f21e37f7ba54ebe82f9f2efe090298d97c46ed469

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page