a
    L9fN  ć                   @   sH   d Z ddlZddlmZ ddlZddlmZ dd ZG dd deZ	dS )	zē
Streamlit Cheat Sheet
App to summarise streamlit docs v0.81.0 for quick reference
There is also an accompanying png version
https://github.com/daniellewisDL/streamlit-cheat-sheet
v0.71.0 November 2020 Daniel Lewis and Austin Chen
é    N)ŚPath)ŚHydraHeadAppc                 C   s   t |  ” }t |” ” }|S ©N)r   Ś
read_bytesŚbase64Ś	b64encodeŚdecode)Zimg_pathZ	img_bytesŚencoded© r
   śF/Users/putuwistika/Documents/TRILAK/hydralit-example/apps/cheat_app.pyŚimg_to_bytes   s    r   c                   @   s.   e Zd ZdddZdd Zdd Zdd	 Zd
S )ŚCheatAppŚ c                 K   s   | j  |” || _d S r   )Ś__dict__ŚupdateŚtitle)Śselfr   Śkwargsr
   r
   r   Ś__init__   s    zCheatApp.__init__c                 C   s   |   ”  |  ”  d S r   )Ś_cs_sidebarŚ_cs_body©r   r
   r
   r   Śrun   s    zCheatApp.runc                 C   s¾   t j d” t jjddd t j d” t j d” t j d” t j d” t j d	” t j d
” t j d” t j d” t j d” t j d” t j d” t jjd td”dd d S )NzStreamlit cheat sheetz
    <small>Summary of the [docs](https://docs.streamlit.io/en/stable/api.html), as of [Streamlit v0.81.0](https://www.streamlit.io/).</small>
        T©Śunsafe_allow_htmlz__How to install and import__z$ pip install streamlitzImport conventionz>>> import streamlit as stz__Add widgets to sidebar__zJ
    st.sidebar.<widget>
    >>> a = st.sidebar.radio('R:',[1,2])
        z__Command line__zĄ
    $ streamlit --help
    $ streamlit run your_script.py
    $ streamlit hello
    $ streamlit config show
    $ streamlit cache clear
    $ streamlit docs
    $ streamlit --version
        z__Pre-release features__zm[Beta and experimental features](https://docs.streamlit.io/en/0.70.0/api.html#beta-and-experimental-features)zQ
    pip uninstall streamlit
    pip install streamlit-nightly --upgrade
        z“[<img src='data:image/png;base64,{}' class='img-fluid' width=32 height=32>](https://github.com/daniellewisDL/streamlit-cheat-sheet) <small>st.cheat_sheet v0.81.0 | May 2021</small>z./resources/brain.png)ŚstŚsidebarŚheaderŚmarkdownŚcodeŚformatr   r   r
   r
   r   r   %   s"    ž
zCheatApp._cs_sidebarc                 C   sD  t  d” t jddd t  d”\}}}| d” | d” | d” | d	” | d
” | d” | d” | d” | d” | d” | d” | d” | d” | d” | d” | d” | d” | d” | d” | d” | d” | d” | d” | d” | d” | d” | d ” | d!” d S )"NaB  Source for this great app is from the Streamlit gallery [Streamlit Cheat Sheet](https://github.com/daniellewisDL/streamlit-cheat-sheet). An example of how easy it is to convert an existing application and use within a Hydralit multi-page application, see the secret saurce [here] (https://github.com/TangleSpace/hydralit).z<br><br>Tr   é   zMagic commandszx# Magic commands implicitly `st.write()`
    ''' _This_ is some __Markdown__ '''
    a=3
    'dataframe:', data
        zDisplay textay  
    st.text('Fixed width text')
    st.markdown('_Markdown_') # see *
    st.latex(r''' e^{i\pi} + 1 = 0 ''')
    st.write('Most objects') # df, err, func, keras!
    st.write(['st', 'is <', 3]) # see *
    st.title('My title')
    st.header('My header')
    st.subheader('My sub')
    st.code('for i in range(8): foo()')
    * optional kwarg unsafe_allow_html = True
        zDisplay datazk
    st.dataframe(my_dataframe)
    st.table(data.iloc[0:10])
    st.json({'foo':'bar','fu':'ba'})
        zDisplay chartsa/  
    st.line_chart(data)
    st.area_chart(data)
    st.bar_chart(data)
    st.pyplot(fig)
    st.altair_chart(data)
    st.vega_lite_chart(data)
    st.plotly_chart(data)
    st.bokeh_chart(data)
    st.pydeck_chart(data)
    st.deck_gl_chart(data)
    st.graphviz_chart(data)
    st.map(data)
        zDisplay mediazL
    st.image('./header.png')
    st.audio(data)
    st.video(data)
        zDisplay interactive widgetsa  
    st.button('Hit me')
    st.checkbox('Check me out')
    st.radio('Radio', [1,2,3])
    st.selectbox('Select', [1,2,3])
    st.multiselect('Multiselect', [1,2,3])
    st.slider('Slide me', min_value=0, max_value=10)
    st.select_slider('Slide to select', options=[1,'2'])
    st.text_input('Enter some text')
    st.number_input('Enter a number')
    st.text_area('Area for textual entry')
    st.date_input('Date input')
    st.time_input('Time entry')
    st.file_uploader('File uploader')
    st.color_picker('Pick a color')
        z*Use widgets' returned values in variables:zŌ
    >>> for i in range(int(st.number_input('Num:'))): foo()
    >>> if st.sidebar.selectbox('I:',['f']) == 'f': b()
    >>> my_slider_val = st.slider('Quinn Mallory', 1, 88)
    >>> st.write(slider_val)
        zControl flowz
    st.stop()
        zLay out your appzą
    st.container()
    st.columns(spec)
    >>> col1, col2 = st.columns(2)
    >>> col1.subheader('Columnisation')
    st.expander('Expander')
    >>> with st.expander('Expand'):
    >>>     st.write('Juicy deets')
        zDisplay codezi
    st.echo()
    >>> with st.echo():
    >>>     st.write('Code will be executed and printed')
        zDisplay progress and statusaP  
    st.progress(progress_variable_1_to_100)
    st.spinner()
    >>> with st.spinner(text='In progress'):
    >>>     time.sleep(5)
    >>>     st.success('Done')
    st.balloons()
    st.error('Error message')
    st.warning('Warning message')
    st.info('Info message')
    st.success('Success message')
    st.exception(e)
        zPlaceholders, help, and optionszŽ
    st.empty()
    >>> my_placeholder = st.empty()
    >>> my_placeholder.text('Replaced!')
    st.help(pandas.DataFrame)
    st.get_option(key)
    st.set_option(key, value)
    st.set_page_config(layout='wide')
        zMutate dataz°
    DeltaGenerator.add_rows(data)
    >>> my_table = st.table(df1)
    >>> my_table.add_rows(df2)
    >>> my_chart = st.line_chart(df1)
    >>> my_chart.add_rows(df2)
        zOptimize performanceaF  
    @st.cache
    >>> @st.cache
    ... def foo(bar):
    ...     # Mutate bar
    ...     return data
    >>> # Executes d1 as first time
    >>> d1 = foo(ref1)
    >>> # Does not execute d1; returns cached value, d1==d2
    >>> d2 = foo(ref1)
    >>> # Different arg, so function d1 executes
    >>> d3 = foo(ref2)
        )r   Ś	subheaderr   Ścolumnsr   Śwrite)r   Ścol1Ścol2Ścol3r
   r
   r   r   T   s@    














	














zCheatApp._cs_bodyN)r   )Ś__name__Ś
__module__Ś__qualname__r   r   r   r   r
   r
   r
   r   r      s   
/r   )
Ś__doc__Ś	streamlitr   Śpathlibr   r   Śhydralitr   r   r   r
   r
   r
   r   Ś<module>   s   