Provides static HTML export for dataframes and altair charts for Streamlit apps.
Project description
Streamlit Static Export
This library will allow Titles, Paragraphs, Dataframes and Altair Charts to be exported into a static HTML file.
PyPi Project
You can access the PyPi project here
Installation
pip install st-static-export
Available Methods
- add_header : Creates a H1-H4 title.
- export_dataframe : Creates a HTML table from your dataframe that can be optionally enclosed in an expander.
- add_text: Allows for a paragraph to be added to the HTML export.
- export_altair_graph: Embeds an Altair chart, including interactions and selections to your HTML file.
- create_html: composes final HTML file and returns a string or bytes.
Usage
import streamlit as st
import st_static_export as sse
import pandas as pd
import altair as alt
#This can be read from a separate file
css_text = """
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
tr:nth-child(even) {background-color: #f2f2f2;}
.table{
width:100%;
}
.footn{
color:#c0c0c0;
}
"""
#Initialize StreamlitStaticExport
static_html = sse.StreamlitStaticExport(css=css_text)
static_html.add_header(id="title",text="Seattle Weather", size="H1" )
static_html.add_header(id="subtitle",text="Dataset from Vegas", size="H3" )
st.title("Seattle Weather")
html.add_text(id="explanation", text="""This is a brief explanation of \n how Seattle weather behaves""", text_class='footn')
df = local_data.seattle_weather()
st.dataframe(df)
html.export_dataframe(id="df", dataframe=df,inside_expandable=True, table_class='table')
base = alt.Chart(df).mark_bar().encode(
x=alt.X('date', type='temporal'),
y=alt.Y('precipitation', type='quantitative'),
color = alt.Color('weather', type ='nominal')
)
st.altair_chart(base, use_container_width=True)
html.export_altair_graph(id="chart",html_content=base.properties(width=900))
#Return a string
str_result = html.create_html(return_type="String")
with open('sample.html', 'w') as b:
b.write(str_result)
#Return Bytes to be attached to a button or other actions.
bt_result = html.create_html(return_type="Bytes")
with open('sample_bytes.html', 'wb') as b:
b.write(bt_result)
Regular Search
Output
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
File details
Details for the file st_static_export-0.2.0.tar.gz
.
File metadata
- Download URL: st_static_export-0.2.0.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 797599bd372d8f25d7ff3073d22a90d950b18fb9b4cdb936a2abf6dbb475a7f0 |
|
MD5 | ca5d870fbe0b7dee443df6ab89bd7450 |
|
BLAKE2b-256 | d004fa5e1a7e7e5e567adab4825d88b11ca9880d9805b333cb3e71c315cbc4f6 |
File details
Details for the file st_static_export-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: st_static_export-0.2.0-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9cb0d9acff34bef1a7e89d1b54bea31d413bb0e08e6f95cf15429088a67788f4 |
|
MD5 | 56272d5ed01ec71a041b301fb0e6af0e |
|
BLAKE2b-256 | 9103040ed5b7083b98a70691f210cf820cc49ccb61a5ed7a7231fdc66fefa280 |