File size: 13,940 Bytes
2482ff6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 |
#######################################################################################################
#Importind required libraries
#######################################################################################################
import streamlit as st
import base64
import sys
from pathlib import Path
script_dir = Path(__file__).resolve().parent
project_root = script_dir.parent
sys.path.append(str(project_root))
#######################################################################################################
#Importing from SRC
#######################################################################################################
from src.Streamlit_Magic_Sheet.components.header import *
from src.Streamlit_Magic_Sheet.components.body import *
from src.Streamlit_Magic_Sheet.components.navigation import *
from src.Streamlit_Magic_Sheet.components.siderbar import *
from src.Streamlit_Magic_Sheet.components.metrics import *
from src.Streamlit_Magic_Sheet.components.charts import *
from src.Streamlit_Magic_Sheet.components.test import *
from src.Streamlit_Magic_Sheet.components.elements import *
#######################################################################################################
# Initial page config
# class whole_app:
# st.set_page_config(
# page_title='Streamlit cheat sheet',
# layout="wide",
# initial_sidebar_state="expanded",
# )
# def main():
# cs_sidebar()
# cs_body()
# return None
# # Thanks to streamlitopedia for the following code snippet
# def img_to_bytes(img_path):
# img_bytes = Path(img_path).read_bytes()
# encoded = base64.b64encode(img_bytes).decode()
# return encoded
# # sidebar
# def cs_sidebar():
# #st.sidebar.markdown('''[<img src='data:image/png;base64,{}' class='img-fluid' width=32 height=32>](https://streamlit.io/)'''.format(img_to_bytes("logomark_website.png")), unsafe_allow_html=True)
# st.sidebar.header('Streamlit cheat sheet')
# st.sidebar.markdown('''
# <small>Summary of the [docs](https://docs.streamlit.io/), as of [Streamlit v1.25.0](https://www.streamlit.io/).</small>
# ''', unsafe_allow_html=True)
# st.sidebar.markdown('__Install and import__')
# st.sidebar.code('$ pip install streamlit')
# st.sidebar.code('''
# # Import convention
# >>> import streamlit as st
# ''')
# st.sidebar.markdown('__Add widgets to sidebar__')
# st.sidebar.code('''
# # Just add it after st.sidebar:
# >>> a = st.sidebar.radio(\'Choose:\',[1,2])
# ''')
# st.sidebar.markdown('__Magic commands__')
# st.sidebar.code('''
# '_This_ is some __Markdown__'
# a=3
# 'dataframe:', data
# ''')
# st.sidebar.markdown('__Command line__')
# st.sidebar.code('''
# $ streamlit --help
# $ streamlit run your_script.py
# $ streamlit hello
# $ streamlit config show
# $ streamlit cache clear
# $ streamlit docs
# $ streamlit --version
# ''')
# st.sidebar.markdown('__Pre-release features__')
# st.sidebar.code('''
# pip uninstall streamlit
# pip install streamlit-nightly --upgrade
# ''')
# st.sidebar.markdown('<small>Learn more about [experimental features](https://docs.streamlit.io/library/advanced-features/prerelease#beta-and-experimental-features)</small>', unsafe_allow_html=True)
# st.sidebar.markdown('''<hr>''', unsafe_allow_html=True)
# st.sidebar.markdown('''<small>[Cheat sheet v1.25.0](https://github.com/daniellewisDL/streamlit-cheat-sheet) | Aug 2023 | [Daniel Lewis](https://daniellewisdl.github.io/)</small>''', unsafe_allow_html=True)
# return None
# ##########################
# # Main body of cheat sheet
# ##########################
# def cs_body():
# col1, col2, col3 = st.columns(3)
# #######################################
# # COLUMN 1
# #######################################
# # Display text
# col1.subheader('Display text')
# col1.code('''
# st.text('Fixed width text')
# st.markdown('_Markdown_') # see #*
# st.caption('Balloons. Hundreds of them...')
# 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
# ''')
# # Display data
# col1.subheader('Display data')
# col1.code('''
# st.dataframe(my_dataframe)
# st.table(data.iloc[0:10])
# st.json({'foo':'bar','fu':'ba'})
# st.metric(label="Temp", value="273 K", delta="1.2 K")
# ''')
# # Display media
# col1.subheader('Display media')
# col1.code('''
# st.image('./header.png')
# st.audio(data)
# st.video(data)
# ''')
# # Columns
# col1.subheader('Columns')
# col1.code('''
# col1, col2 = st.columns(2)
# col1.write('Column 1')
# col2.write('Column 2')
# # Three columns with different widths
# col1, col2, col3 = st.columns([3,1,1])
# # col1 is wider
# # Using 'with' notation:
# >>> with col1:
# >>> st.write('This is column 1')
# ''')
# # Tabs
# col1.subheader('Tabs')
# col1.code('''
# # Insert containers separated into tabs:
# >>> tab1, tab2 = st.tabs(["Tab 1", "Tab2"])
# >>> tab1.write("this is tab 1")
# >>> tab2.write("this is tab 2")
# # You can also use "with" notation:
# >>> with tab1:
# >>> st.radio('Select one:', [1, 2])
# ''')
# # Control flow
# col1.subheader('Control flow')
# col1.code('''
# # Stop execution immediately:
# st.stop()
# # Rerun script immediately:
# st.experimental_rerun()
# # Group multiple widgets:
# >>> with st.form(key='my_form'):
# >>> username = st.text_input('Username')
# >>> password = st.text_input('Password')
# >>> st.form_submit_button('Login')
# ''')
# # Personalize apps for users
# col1.subheader('Personalize apps for users')
# col1.code('''
# # Show different content based on the user's email address.
# >>> if st.user.email == '[email protected]':
# >>> display_jane_content()
# >>> elif st.user.email == '[email protected]':
# >>> display_adam_content()
# >>> else:
# >>> st.write("Please contact us to get access!")
# ''')
# #######################################
# # COLUMN 2
# #######################################
# # Display interactive widgets
# col2.subheader('Display interactive widgets')
# col2.code('''
# st.button('Hit me')
# st.data_editor('Edit data', data)
# st.checkbox('Check me out')
# st.radio('Pick one:', ['nose','ear'])
# 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.download_button('On the dl', data)
# st.camera_input("一二三,茄子!")
# st.color_picker('Pick a color')
# ''')
# col2.code('''
# # Use widgets\' returned values in variables
# >>> 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)
# ''')
# col2.code('''
# # Disable widgets to remove interactivity:
# >>> st.slider('Pick a number', 0, 100, disabled=True)
# ''')
# # Build chat-based apps
# col2.subheader('Build chat-based apps')
# col2.code('''
# # Insert a chat message container.
# >>> with st.chat_message("user"):
# >>> st.write("Hello 👋")
# >>> st.line_chart(np.random.randn(30, 3))
# # Display a chat input widget.
# >>> st.chat_input("Say something")
# ''')
# col2.markdown('<small>Learn how to [build chat-based apps](https://docs.streamlit.io/knowledge-base/tutorials/build-conversational-apps)</small>', unsafe_allow_html=True)
# # Mutate data
# col2.subheader('Mutate data')
# col2.code('''
# # Add rows to a dataframe after
# # showing it.
# >>> element = st.dataframe(df1)
# >>> element.add_rows(df2)
# # Add rows to a chart after
# # showing it.
# >>> element = st.line_chart(df1)
# >>> element.add_rows(df2)
# ''')
# # Display code
# col2.subheader('Display code')
# col2.code('''
# st.echo()
# >>> with st.echo():
# >>> st.write('Code will be executed and printed')
# ''')
# # Placeholders, help, and options
# col2.subheader('Placeholders, help, and options')
# col2.code('''
# # Replace any single element.
# >>> element = st.empty()
# >>> element.line_chart(...)
# >>> element.text_input(...) # Replaces previous.
# # Insert out of order.
# >>> elements = st.container()
# >>> elements.line_chart(...)
# >>> st.write("Hello")
# >>> elements.text_input(...) # Appears above "Hello".
# st.help(pandas.DataFrame)
# st.get_option(key)
# st.set_option(key, value)
# st.set_page_config(layout='wide')
# st.experimental_show(objects)
# st.experimental_get_query_params()
# st.experimental_set_query_params(**params)
# ''')
# #######################################
# # COLUMN 3
# #######################################
# # Connect to data sources
# col3.subheader('Connect to data sources')
# col3.code('''
# st.experimental_connection('pets_db', type='sql')
# conn = st.experimental_connection('sql')
# conn = st.experimental_connection('snowpark')
# >>> class MyConnection(ExperimentalBaseConnection[myconn.MyConnection]):
# >>> def _connect(self, **kwargs) -> MyConnection:
# >>> return myconn.connect(**self._secrets, **kwargs)
# >>> def query(self, query):
# >>> return self._instance.query(query)
# ''')
# # Optimize performance
# col3.subheader('Optimize performance')
# col3.write('Cache data objects')
# col3.code('''
# # E.g. Dataframe computation, storing downloaded data, etc.
# >>> @st.cache_data
# ... def foo(bar):
# ... # Do something expensive and return data
# ... return data
# # Executes foo
# >>> d1 = foo(ref1)
# # Does not execute foo
# # Returns cached item by value, d1 == d2
# >>> d2 = foo(ref1)
# # Different arg, so function foo executes
# >>> d3 = foo(ref2)
# # Clear all cached entries for this function
# >>> foo.clear()
# # Clear values from *all* in-memory or on-disk cached functions
# >>> st.cache_data.clear()
# ''')
# col3.write('Cache global resources')
# col3.code('''
# # E.g. TensorFlow session, database connection, etc.
# >>> @st.cache_resource
# ... def foo(bar):
# ... # Create and return a non-data object
# ... return session
# # Executes foo
# >>> s1 = foo(ref1)
# # Does not execute foo
# # Returns cached item by reference, s1 == s2
# >>> s2 = foo(ref1)
# # Different arg, so function foo executes
# >>> s3 = foo(ref2)
# # Clear all cached entries for this function
# >>> foo.clear()
# # Clear all global resources from cache
# >>> st.cache_resource.clear()
# ''')
# col3.write('Deprecated caching')
# col3.code('''
# >>> @st.cache
# ... def foo(bar):
# ... # Do something expensive in here...
# ... return data
# >>> # Executes foo
# >>> d1 = foo(ref1)
# >>> # Does not execute foo
# >>> # Returns cached item by reference, d1 == d2
# >>> d2 = foo(ref1)
# >>> # Different arg, so function foo executes
# >>> d3 = foo(ref2)
# ''')
# # Display progress and status
# col3.subheader('Display progress and status')
# col3.code('''
# # Show a spinner during a process
# >>> with st.spinner(text='In progress'):
# >>> time.sleep(3)
# >>> st.success('Done')
# # Show and update progress bar
# >>> bar = st.progress(50)
# >>> time.sleep(3)
# >>> bar.progress(100)
# st.balloons()
# st.snow()
# st.toast('Mr Stay-Puft')
# st.error('Error message')
# st.warning('Warning message')
# st.info('Info message')
# st.success('Success message')
# st.exception(e)
# ''')
# return None
class test_1:
def __init__(self):
pass
def func_1(self):
st.write("test func_1")
def cs_sidebar(self):
st.write("test t")
def cs_sidebar2(self):
st.write("test t2")
|