"""This app explores the tables of streamlit and if we could provide better tables""" import pathlib import zipfile import pandas as pd import plotly.graph_objects as go import streamlit as st LOCAL_ROOT = pathlib.Path.cwd() / "gallery" / "table_experiments" GITHUB_ROOT = "https://raw.githubusercontent.com/MarcSkovMadsen/awesome-analytics-apps/master/gallery/table_experiments/" ZIP_FILE_2019 = "developer_survey_2019.zip" RESULTS_2019 = "survey_results_public.csv" SCHEMA_2019 = "survey_results_schema.csv" DEFAULT_NUMBER_OF_ROWS = 5 DEFAULT_NUMBER_OF_COLUMNS = 5 def main(): st.title("Table Experiments") st.markdown( """ The purpose of this app is to explore the possibilities for showing and working with tables in Streamlit NOTE. THIS IS WORK IN PROGRESS. FEEL FREE TO CONTRIBUTE. """ ) results = read_results() st.header("Possibilities for showing and working with dataframe") table_type = st.radio( "Select table type", options=[ "Streamlit dataframe", "Streamlit table", "Plotly table", "Slick Grid", ], ) if table_type == "Streamlit dataframe": streamlit_dataframe(results) elif table_type == "Streamlit table": streamlit_table(results) elif table_type == "Plotly table": plotly_table(results) else: slick_grid(results) def streamlit_dataframe(results): st.subheader("Streamlit Dataframe (st.dataframe)") number_of_rows, number_of_columns, style = select_number_of_rows_and_columns( results, key="st.dataframe" ) filter_table = filter_results(results, number_of_rows, number_of_columns, style) st.dataframe(filter_table) st.markdown( """ Pros - Can sort - Can maximize - Can transfer and display 10.000 rows and 5 columns in 3 seconds. - Can style cells using [dataframe.style.set_properties](https://pandas.pydata.org/pandas-docs/stable/user_guide/style.html) Cons - Cannot filter - Cannot style table (including header) using [dataframe.style.set_table_styles] (https://pandas.pydata.org/pandas-docs/stable/user_guide/style.html) - Cannot change column width, aligment or similar. - The scrollbar is *thin* and can be difficult to select/ drag. """ ) def streamlit_table(results): st.subheader("Streamlit Table (st.table)") number_of_rows, number_of_columns, style = select_number_of_rows_and_columns( results, key="st.table" ) filter_table = filter_results(results, number_of_rows, number_of_columns, style) st.table(filter_table) st.markdown( """ Pros - Can transfer and display 5.000 rows and 5 columns in 5 seconds. - Can style cells using [dataframe.style.set_properties](https://pandas.pydata.org/pandas-docs/stable/user_guide/style.html) Cons - Cannot sort or filter - Cannot maximize - No scrollbar - Cannot style table (including header) using [dataframe.style.set_table_styles] (https://pandas.pydata.org/pandas-docs/stable/user_guide/style.html) - Cannot change column width, aligment or similar. """ ) def plotly_table(results): st.header("Plotly Table (go.Table)") number_of_rows, number_of_columns, style = select_number_of_rows_and_columns( results, key="go.Table" ) filter_table = _filter_results(results, number_of_rows, number_of_columns) header_values = list(filter_table.columns) cell_values = [] for index in range(0, len(filter_table.columns)): cell_values.append(filter_table.iloc[:, index : index + 1]) if not style: fig = go.Figure( data=[ go.Table( header=dict(values=header_values), cells=dict(values=cell_values) ) ] ) else: fig = go.Figure( data=[ go.Table( header=dict( values=header_values, fill_color="paleturquoise", align="left" ), cells=dict(values=cell_values, fill_color="lavender", align="left"), ) ] ) st.plotly_chart(fig) st.markdown( """ Pros - Can maximize - Can transfer and display 10.000 rows and 5 columns in 10000 seconds. - Can do advanced styling and layout. Cons - Cannot sort or filter - The scrollbar is *thin* and can be difficult to select/ drag. References: - [Plotly Table Introduction](https://plot.ly/python/table/) - [Plotly Table Reference](https://plot.ly/python/reference/#table) """ ) def slick_grid(results): st.header("Slickgrid") st.markdown( """ The SlickGrid example does not work because I cannot inject javascript tags. References: - [SlickGrid](https://slickgrid.net/) - [SlickGrid examples](https://github.com/mleibman/SlickGrid/tree/gh-pages/examples) """ ) st.markdown( """
Demonstrates:
View Source: |