datastack
- class datastack.stacker.stacker.datastack(type='main_page', path='', title='', main=False, wide_mode=True)
Bases:
objectDatastack class for holding all widgets
- Parameters:
type (str main_page | sidebar | container | column | tab | None) –
path (str) – Path for pages
title (str) – Title of container or tabs
main (bool) – True value idenfify the class instance as main class where as false value identify as subclass
- append_block(block, location='main_page')
- b_b(block)
- build_app()
- build_element_from_blocks(blocks)
- build_element_from_blocks_1(blocks)
- button(name: str, on_click: callable | None = None, args: Tuple | None = None, id: str | None = None)
Button widget.
- Parameters:
name (str) – A name of button, clerly explain the purpouse of button to user.
on_click (callable) – callable function to invoke when button is clicked
args (tuple) – An optional tuple of args to pass to the callback.
Examples
Simple button
>>> ds.button('Click')
Button on_click
>>> count = 0 >>> >>> def click(): ... global count ... count += 1 >>> >>> ds.button('Click', on_click=click) >>> ds.write('Count = {}'.format(count), id='count')
- cache_data(func: callable)
Decorator to cache functions that return data
- Parameters:
func (callable) – the function to cache
Examples
>>> @ds.cache_data >>> def get_data(): ... # fetch data from db ... return 'some_data' ... >>> get_data()
- chart(data, on_click: callable | None = None, id: str | None = None)
Display plotly chart
- Parameters:
data (plotly data) – plotly fig object to display chart
id (str) – An optional string or integer to use as the unique key for the element.
Examples
>>> import plotly.express as px ... >>> data_canada = px.data.gapminder().query("country == 'Canada'") >>> fig = px.bar(data_canada, x='year', y='pop') ... >>> ds.subheader('Charts') >>> ds.chart(fig)
>>> import plotly.express as px ... >>> df = px.data.tips() ... >>> fig = px.box(df, x="day", y="total_bill", facet_row="smoker") >>> fig.update_traces(quartilemethod="exclusive", alignmentgroup='df', offsetgroup='offset') >>> fig.update_layout(boxmode='group') ... >>> ds.chart(fig)
- chart_builder(id='')
- clear_notifications()
Clear all notifications
- code(data: str, id: str | None = None)
Display code element
- Parameters:
data (str) – Code as string to display
id (str) – An optional string or integer to use as the unique key for the element.
Examples
>>> ds.code('''def my_function(): ... print('my function')''')
- columns(col_number: int, id: str | None = None)
Insert containers laid out as side-by-side columns
- Parameters:
col_number (int) – number of columns required
id (str) – An optional string or integer to use as the unique key for the element.
Examples
>>> col1, col2, col3 = ds.columns(3) >>> col1.write('this is col1') >>> col2.write('this is col2') >>> col3.write('this is col3')
- container()
Insert a multi-element container.
Examples
>>> container = ds.container() >>> ds.write('This is outside container') ... >>> container.write('this is inside container' )
- dataframe(data, id: str | None = None)
Display dataframe
- Parameters:
data (pandas.DataFrame) – The data to display
id (str) – An optional string or integer to use as the unique key for the element.
Examples
>>> import pandas as pd >>> import numpy as np ... >>> df = pd.DataFrame(np.random.randn(25,10), columns=("col_%d" % i for i in range(10))) ... >>> ds.dataframe(df.round(decimals=3))
- date_input(label: str = None, value: str = None, min: str = '1970-01-01', max: str = '2500-01-01', date_format: str = 'yyyy-MM-dd', use_container_width: bool = False, disabled: bool = False, id: str | None = None, on_change: callable | None = None)
Display a date input element.
- Parameters:
label (str) – A short label explaining to the user what this date input is for.
value (str) – The value of this widget when it first renders (ex.: 2023-01-01).
min (str) – The minimum selectable date (ex.: 2023-01-01).
max (str) – The maximum selectable date (ex.: 2023-01-01).
date_format (str) – To set the date format (ex.: dd-MMM-yyyy).
use_container_width (bool) – An optional boolean, which makes the date picker stretch its width to match the parent container.
disabled (bool) – An optional boolean, which disables the date input if set to True. The default is False.
id (str) – An optional string or integer to use as the unique key for the element.
on_change (callable) – An option callback invoked when this text input’s value chnages.
Examples
>>> ds.date_input()
- divider()
A divider line separates different content.
Examples
>>> ds.divider()
- dump_app()
- dynamic_widget_id()
- editable_html(key, id='')
- error(text: str = None, id: str | None = None)
Display an error message.
- Parameters:
text (str) – The info text to display
id (str) – An optional string or integer to use as the unique key for the element.
Examples
>>> ds.error('This is an error!')
- expander(name: str)
A content area which can be collapsed and expanded.
- Parameters:
name (str) – name of the expander
Examples
>>> expander = ds.expander('Expand to view content') >>> expander.write('This content will show inside the expander')
- gat_all_blocks()
- get_all_dfs()
- get_app_block_by_id(id)
- get_block_by_id(id)
- header(data, id: str | None = None)
Display text in header formatting.
- Parameters:
data (str) – The text to display
id (str) – An optional string or integer to use as the unique key for the element.
Examples
>>> ds.header('This is header')
- html(html: str, allow_unsafe_html: bool = False, id: str | None = None)
Diapy html element
- Parameters:
html (str) – html string
allow_unsafe_html (bool) – By default, any HTML tags found in the body will be escaped and therefore treated as pure text. This behavior may be turned off by setting this argument to True.
id (str) – An optional string or integer to use as the unique key for the element.
Examples
>>> ds.html("<h1>Header</h1>")
- iframe(url: str, id: str | None = None)
Display iframe element
- Parameters:
url (str) – url for iframe
id (str) – An optional string or integer to use as the unique key for the element.
Examples
>>> ds.subheader('Iframe') ... >>> url = 'https://www.wikipedia.org/' >>> ds.iframe(url)
- image(data, id: str | None = None)
Diaplay an image
- Parameters:
data (ImageFile) – image data to display
id (str) – An optional string or integer to use as the unique key for the element.
Examples
>>> import os >>> from PIL import Image >>> image = Image.open(os.path.join('images', 'image-3.png')) >>> ds.image(image)
- info(text: str = None, id: str | None = None)
Display an informational message.
- Parameters:
text (str) – The info text to display
id (str) – An optional string or integer to use as the unique key for the element.
Examples
>>> ds.info('Data saved')
- input(label: str = None, value: str | None = '', id: str | None = None, on_change: callable | None = '', args: Tuple | None = None)
Display a single-line text input widget
- Parameters:
label (str) – A short label explaining to the user what this input is for.
value (str or None) – The text value of this element when it first renders.
id (str) – An optional string or integer to use as the unique key for the element.
on_change (callable) – An option callback invoked when this text input’s value chnages.
args (dict) – An optional tuple of args to pass to the callback
Examples
>>> name = ds.input('Name') >>> ds.write('your name: ' + name)
- list(data: Iterable = [], on_click: Callable | None = None, id: str | None = None)
Display list element
- Parameters:
data (Iterable) – Iterable list to display
on_click (Callable) – An option callback invoked when this list is clicked.
id (str) – An optional string or integer to use as the unique key for the element.
Examples
>>> selected_lan = ds.list(['python', 'javascript', 'java', 'c++', 'pascal']) >>> ds.write('your favourite language: ' + selected_lan)
- markdown(data: str, id: str | None = None)
Display markdown text
- Parameters:
data (str) – data to display
id (str) – An optional string or integer to use as the unique key for the element.
Examples
>>> ds.markdown("**bold text** *itlic text*") >>> ds.markdown("# A first-level heading") >>> ds.markdown("## A second-level heading") >>> ds.markdown("### A third-level heading")
Display menu
- Parameters:
data (Iterable) – data to be displayed in the menu.
mode (vertical | horizontal | inline) – Mode of menu display
value (str or None) – The text value of this element when it first renders.
id (str) – An optional string or integer to use as the unique key for the element.
on_change (callable) – An option callback invoked when this text input’s value chnages.
Examples
>>> page = ds.menu(['Page1', 'Page2', 'Page3']) >>> ds.header(page)
- notification(data: str)
Diaplay a short message
- Parameters:
data (str) – The string to display
- page(path: str)
create a new page
- Parameters:
path (str) – Path of page
Examples
>>> page1 = ds.page('page1')
- page_link(page_name, id='')
- pyplot(fig)
Display a matplotlib.pyplot figure.
- Parameters:
fig (Matplotlib Figure) – The figure to plot.
Examples
>>> import numpy as np >>> ds.subheader('PyPlot') >>> arr = np.random.normal(1, 1, size=100) >>> import matplotlib.pyplot as plt >>> fig, ax = plt.subplots() >>> ax.hist(arr, bins=20) >>> ds.pyplot(fig)
- query(data, id='')
- radio_button(label: str = '', options: Iterable = [], value: str | None = '', id: str | None = None, on_change: callable | None = '', args: Tuple | None = None)
Display a radio button element
- Parameters:
label (str) – A short label explaining to the user what this input is for.
options (Itrerable) – Options for select element.
value (str or None) – The text value of this element when it first renders.
id (str) – An optional string or integer to use as the unique key for the element.
on_change (callable) – An option callback invoked when this text input’s value chnages.
args (dict) – An optional tuple of args to pass to the callback
Examples
>>> operating_system = ds.radio_button('Select operating system', ['ios', 'android', 'windows']) >>> ds.write('You selected: ' + operating_system)
- replace_block(id, new_block)
- rerun(my_vars={}, old_app='')
- select(label: str, options: Iterable = [], value: str | None = '', id: str | None = None, on_change: callable | None = '', args: Tuple | None = None)
Select component to select value from options
- Parameters:
label (str) – A short label explaining to the user what this input is for.
options (Itrerable) – Options for select element.
value (str or None) – The text value of this element when it first renders.
id (str) – An optional string or integer to use as the unique key for the element.
on_change (callable) – An option callback invoked when this text input’s value chnages.
args (dict) – An optional tuple of args to pass to the callback
Examples
>>> operating_system = ds.select('Select operating system', ['ios', 'android', 'windows']) >>> ds.write('You selected: ' + operating_system)
- set_page(page_name: str)
Set which page to display
- Parameters:
page_name (str) – page name
Examples
>>> ds.set_page('page1')
- sidebar()
Sidebar
- slider(min: int, max: int, value: int = None, id: str | None = None, on_change: callable | None = None)
Display a slider element.
- Parameters:
min (int) – minimum value of slider
max (int) – maximum value of slider
value (str or None) – The text value of this element when it first renders.
id (str) – An optional string or integer to use as the unique key for the element.
on_change (callable) – An option callback invoked when this text input’s value chnages.
Examples
>>> ds.slider(min=10, max=100, value=50)
- sql_connection(params)
- subheader(data, id: str | None = None)
Display text in subheader formatting.
- Parameters:
data (str) – The text to display
id (str) – An optional string or integer to use as the unique key for the element.
Examples
>>> ds.subheader('This is subheader')
- success(text: str = None, id: str | None = None)
Display an informational message.
- Parameters:
text (str) – The success text to display
id (str) – An optional string or integer to use as the unique key for the element.
Examples
>>> ds.success('Data saved')
- table(data, column_definition: dict = {}, editable_columns: str | None = None, id: str | None = None)
Display a dataframe as an interactive table.
- Parameters:
data (pandas.DataFrame) – The data to display.
column_defination (dict) – define columns
editable_columns –
id (str) – An optional string or integer to use as the unique key for the element.
Examples
>>> import pandas as pd >>> data = [ ... {'name':'Ikigai', 'author':'Francesc Miralles and Hector Garcia', 'rating':4.3 }, ... {'name':'psychology of money', 'author':'Morgan Housel', 'rating':4.5}, ... {'name':'Atomic Habits', 'author':'James Clear', 'rating':4.4}, ... {'name':'Rework', 'author':"David Heinemeier Hansson and Jason Fried", 'rating':4.5} ] >>> df = pd.json_normalize(data) >>> ds.table(df)
- tabs(tab_list: Iterable, id: str | None = None)
Insert containers separated into tabs.
- Parameters:
tab_list (iterable) – list of tabs to display
id (str) – An optional string or integer to use as the unique key for the element.
Examples
>>> tab1, tab2, tab3 = ds.tabs(["tab1","tab2", "tab3"]) >>> tab1.header('Tab1') >>> tab1.write('this is tab1') >>> tab2.header('Tab2') >>> tab2.write('this is tab2') >>> tab3.header('Tab3') >>> tab3.write('this is tab3')
- tag(data: str)
Display tag element
- Parameters:
data (str) – text to display inside tag element
Examples
>>> ds.tag('tag1') >>> ds.tag('tag2') >>> ds.tag('tag3') >>> ds.tag('tag4')
- topbar()
Topbar
- update_app_state(key, value)
- update_state()
- warning(text: str = None, id: str | None = None)
Display an warning message.
- Parameters:
text (str) – The info text to display
id (str) – An optional string or integer to use as the unique key for the element.
Examples
>>> ds.warning('This is a warning!')
- write(data, id: str | None = None)
Write text to the app.
- Parameters:
data (str) – text to display
id (str) – An optional string or integer to use as the unique key for the element.
Examples
Basic use case
>>> ds.write('Hello, World!')