@@ -38,6 +38,20 @@ Table of Contents
38
38
* [ PyCaretとStreamlitでAutoMLのGUIツールをさくっと作ってみる] ( #pycaretとstreamlitでautomlのguiツールをさくっと作ってみる )
39
39
* [ 【Streamlit】JavaScriptが嫌いだからPythonだけでWebアプリをつくる] ( #streamlitjavascriptが嫌いだからpythonだけでwebアプリをつくる )
40
40
* [ WEBUIを使ってインタラクティブなアプリにする] ( #webuiを使ってインタラクティブなアプリにする )
41
+ * [ Streamlit極簡易的Dashboard開發 - Neutron] ( #streamlit極簡易的dashboard開發---neutron )
42
+ * [ Streamlit 概念] ( #streamlit-概念 )
43
+ * [ Streamlitを用いた音響信号処理ダッシュボードの開発(Tokyo BISH Bash #03 発表資料)] ( #streamlitを用いた音響信号処理ダッシュボードの開発tokyo-bish-bash-03発表資料 )
44
+ * [ Python: Streamlit を使って手早く WebUI 付きのプロトタイプを作る] ( #python-streamlit-を使って手早く-webui-付きのプロトタイプを作る )
45
+ * [ Column] ( #column )
46
+ * [ container] ( #container )
47
+ * [ Expander] ( #expander )
48
+ * [ Sidebar] ( #sidebar )
49
+ * [ Help] ( #help )
50
+ * [ 単一のスクリプトで複数のアプリケーションを扱う] ( #単一のスクリプトで複数のアプリケーションを扱う )
51
+ * [ Argparse] ( #argparse )
52
+ * [ Click] ( #click )
53
+ * [ cdsdashboards] ( #cdsdashboards )
54
+ * [ Streamlit Offical API] ( #streamlit-offical-api )
41
55
* [ Troubleshooting] ( #troubleshooting )
42
56
* [ Reference] ( #reference )
43
57
* [ h1 size] ( #h1-size )
@@ -49,6 +63,7 @@ Table of Contents
49
63
50
64
Created by [ gh-md-toc] ( https://github.com/ekalinin/github-markdown-toc )
51
65
66
+
52
67
# Purpose
53
68
Take note of Webscreenshoot
54
69
@@ -388,6 +403,311 @@ bodyの場合はst.コンポーネント名、サイドバーにの場合、st.s
388
403
<img src =" https://miro.medium.com/max/2000/1*lU7YeppmSvFiZmEkUDX06w.png " width =" 700 " height =" 500 " >
389
404
390
405
406
+ # Streamlitを用いた音響信号処理ダッシュボードの開発(Tokyo BISH Bash #03 発表資料)
407
+ [ Streamlitを用いた音響信号処理ダッシュボードの開発(Tokyo BISH Bash #03 発表資料) 2020-10-13] ( https://www.hiromasa.info/posts/22/ )
408
+ [ wrist /streamlit-dsp ] ( https://github.com/wrist/streamlit-dsp )
409
+
410
+ [ window_viwer.py] ( https://github.com/wrist/streamlit-dsp/blob/master/streamlit_dsp/window_viewer.py )
411
+
412
+ # Python: Streamlit を使って手早く WebUI 付きのプロトタイプを作る
413
+ [ Python: Streamlit を使って手早く WebUI 付きのプロトタイプを作る 2021-05-14] ( https://blog.amedama.jp/entry/streamlit-tutorial )
414
+
415
+ ## Column
416
+ [ カラム] ( https://blog.amedama.jp/entry/streamlit-tutorial#%E3%82%AB%E3%83%A9%E3%83%A0 )
417
+ ```
418
+ # -*- coding: utf-8 -*-
419
+
420
+ import streamlit as st
421
+
422
+
423
+ def main():
424
+ # カラムを追加する
425
+ col1, col2, col3 = st.beta_columns(3)
426
+
427
+ # コンテキストマネージャとして使う
428
+ with col1:
429
+ st.header('col1')
430
+
431
+ with col2:
432
+ st.header('col2')
433
+
434
+ with col3:
435
+ st.header('col3')
436
+
437
+ # カラムに直接書き込むこともできる
438
+ col1.write('This is column 1')
439
+ col2.write('This is column 2')
440
+ col3.write('This is column 3')
441
+
442
+
443
+ if __name__ == '__main__':
444
+ main()
445
+ ```
446
+ <img src =" https://cdn-ak.f.st-hatena.com/images/fotolife/m/momijiame/20210511/20210511184758.png " width =" 600 " height =" 400 " >
447
+
448
+ ## container
449
+ [ コンテナ] ( https://blog.amedama.jp/entry/streamlit-tutorial#%E3%82%B3%E3%83%B3%E3%83%86%E3%83%8A )
450
+ ```
451
+ # -*- coding: utf-8 -*-
452
+
453
+ import streamlit as st
454
+
455
+
456
+ def main():
457
+ # コンテナを追加する
458
+ container = st.beta_container()
459
+
460
+ # コンテキストマネージャとして使うことで出力先になる
461
+ with container:
462
+ st.write('This is inside the container')
463
+ # これはコンテナの外への書き込み
464
+ st.write('This is outside the container')
465
+
466
+ # コンテナに直接書き込むこともできる
467
+ container = st.beta_container()
468
+ container.write('1')
469
+ st.write('2')
470
+ # 出力順は後だがレイアウト的にはこちらが先に現れる
471
+ container.write('3')
472
+
473
+
474
+ if __name__ == '__main__':
475
+ main()
476
+ ```
477
+ <img src =" https://cdn-ak.f.st-hatena.com/images/fotolife/m/momijiame/20210511/20210511185155.png " width =" 600 " height =" 400 " >
478
+
479
+ ```
480
+ # -*- coding: utf-8 -*-
481
+
482
+ import streamlit as st
483
+
484
+
485
+ def main():
486
+ placeholder = st.empty()
487
+ # プレースホルダにコンテナを追加する
488
+ container = placeholder.beta_container()
489
+ # コンテナにカラムを追加する
490
+ col1, col2 = container.beta_columns(2)
491
+ # それぞれのカラムに書き込む
492
+ with col1:
493
+ st.write('Hello, World')
494
+ with col2:
495
+ st.write('Konnichiwa, Sekai')
496
+
497
+
498
+ if __name__ == '__main__':
499
+ main()
500
+ ```
501
+ <img src =" https://cdn-ak.f.st-hatena.com/images/fotolife/m/momijiame/20210511/20210511185307.png " width =" 600 " height =" 400 " >
502
+
503
+
504
+ ## Expander
505
+ [ エキスパンダ] ( https://blog.amedama.jp/entry/streamlit-tutorial#%E3%82%A8%E3%82%AD%E3%82%B9%E3%83%91%E3%83%B3%E3%83%80 )
506
+ ```
507
+ # -*- coding: utf-8 -*-
508
+
509
+ import streamlit as st
510
+
511
+
512
+ def main():
513
+ with st.beta_expander('See details'):
514
+ st.write('Hidden item')
515
+
516
+
517
+ if __name__ == '__main__':
518
+ main()
519
+ ```
520
+ <img src =" https://cdn-ak.f.st-hatena.com/images/fotolife/m/momijiame/20210511/20210511185400.png " width =" 600 " height =" 400 " >
521
+
522
+ ## Sidebar
523
+ [ サイドバー] ( https://blog.amedama.jp/entry/streamlit-tutorial#%E3%82%B5%E3%82%A4%E3%83%89%E3%83%90%E3%83%BC )
524
+
525
+ ```
526
+ ウィジェットやオブジェクトの表示をサイドバーに配置することもできる。 使い方は単純で、サイドバーに置きたいなと思ったら sidebar をつけて API を呼び出す。
527
+
528
+ 以下のサンプルコードでは、サイドバーにボタンを配置している。 前述したとおり、streamlit.button() を streamlit.sidebar.button() に変えるだけ。 同様に、streamlit.sidebar.dataframe() のように間に sidebar をはさむことで大体の要素はサイドバーに置ける。
529
+ ```
530
+
531
+ ```
532
+ # -*- coding: utf-8 -*-
533
+
534
+ import streamlit as st
535
+ import pandas as pd
536
+ import numpy as np
537
+
538
+
539
+ def main() :
540
+ # サイドバーにリロードボタンをつける
541
+ st.sidebar.button('Reload')
542
+ # サイドバーにデータフレームを書き込む
543
+ data = np.random.randn(20, 3)
544
+ df = pd.DataFrame(data, columns=['x', 'y', 'z'])
545
+ st.sidebar.dataframe(df)
546
+
547
+
548
+ if __name__ == '__main__':
549
+ main()
550
+ ```
551
+ <img src =" https://cdn-ak.f.st-hatena.com/images/fotolife/m/momijiame/20210512/20210512222116.png " width =" 600 " height =" 400 " >
552
+
553
+ ## Help
554
+ [ オブジェクトの docstring を表示する] ( https://blog.amedama.jp/entry/streamlit-tutorial#%E3%82%AA%E3%83%96%E3%82%B8%E3%82%A7%E3%82%AF%E3%83%88%E3%81%AE-docstring-%E3%82%92%E8%A1%A8%E7%A4%BA%E3%81%99%E3%82%8B )
555
+ ```
556
+ # -*- coding: utf-8 -*-
557
+
558
+ import pandas as pd
559
+
560
+ import streamlit as st
561
+
562
+
563
+ def main():
564
+ st.help(pd.DataFrame)
565
+
566
+
567
+ if __name__ == '__main__':
568
+ main()
569
+ ```
570
+ <img src =" https://cdn-ak.f.st-hatena.com/images/fotolife/m/momijiame/20210512/20210512222544.png " width =" 600 " height =" 400 " >
571
+
572
+ ## 単一のスクリプトで複数のアプリケーションを扱う
573
+ ```
574
+ # -*- coding: utf-8 -*-
575
+
576
+ import streamlit as st
577
+
578
+
579
+ def render_gup():
580
+ """GuP のアプリケーションを処理する関数"""
581
+ character_and_quotes = {
582
+ 'Miho Nishizumi': 'パンツァーフォー',
583
+ 'Saori Takebe': 'やだもー',
584
+ 'Hana Isuzu': '私この試合絶対勝ちたいです',
585
+ 'Yukari Akiyama': '最高だぜ!',
586
+ 'Mako Reizen': '以上だ',
587
+ }
588
+ selected_items = st.multiselect('What are your favorite characters?',
589
+ list(character_and_quotes.keys()))
590
+ for selected_item in selected_items:
591
+ st.write(character_and_quotes[selected_item])
592
+
593
+
594
+ def render_aim_for_the_top():
595
+ """トップ!のアプリケーションを処理する関数"""
596
+ selected_item = st.selectbox('Which do you like more in the series?',
597
+ [1, 2])
598
+ if selected_item == 1:
599
+ st.write('me too!')
600
+ else:
601
+ st.write('2 mo ii yo ne =)')
602
+
603
+
604
+ def main():
605
+ # アプリケーション名と対応する関数のマッピング
606
+ apps = {
607
+ '-': None,
608
+ 'GIRLS und PANZER': render_gup,
609
+ 'Aim for the Top! GunBuster': render_aim_for_the_top,
610
+ }
611
+ selected_app_name = st.sidebar.selectbox(label='apps',
612
+ options=list(apps.keys()))
613
+
614
+ if selected_app_name == '-':
615
+ st.info('Please select the app')
616
+ st.stop()
617
+
618
+ # 選択されたアプリケーションを処理する関数を呼び出す
619
+ render_func = apps[selected_app_name]
620
+ render_func()
621
+
622
+
623
+ if __name__ == '__main__':
624
+ main()
625
+ ```
626
+ <img src =" https://cdn-ak.f.st-hatena.com/images/fotolife/m/momijiame/20210512/20210512223221.png " width =" 600 " height =" 400 " >
627
+
628
+ <img src =" https://cdn-ak.f.st-hatena.com/images/fotolife/m/momijiame/20210512/20210512223230.png " width =" 600 " height =" 400 " >
629
+
630
+ <img src =" https://cdn-ak.f.st-hatena.com/images/fotolife/m/momijiame/20210512/20210512223239.png " width =" 600 " height =" 400 " >
631
+
632
+
633
+ ## Argparse
634
+ ```
635
+ # -*- coding: utf-8 -*-
636
+
637
+ import argparse
638
+
639
+ import streamlit as st
640
+
641
+
642
+ def main():
643
+ parser = argparse.ArgumentParser(description='parse argument example')
644
+ # --message または -m オプションで文字列を受け取る
645
+ parser.add_argument('--message', '-m', type=str, default='World')
646
+ # 引数をパースする
647
+ args = parser.parse_args()
648
+ # パースした引数を表示する
649
+ st.write(f'Hello, {args.message}!')
650
+
651
+
652
+ if __name__ == '__main__':
653
+ main()
654
+ ```
655
+
656
+ ```
657
+ $ streamlit run example.py -m Sekai
658
+ Usage: streamlit run [OPTIONS] TARGET [ARGS]...
659
+ Try 'streamlit run --help' for help.
660
+
661
+ Error: no such option: -m
662
+ ```
663
+
664
+ ```
665
+ $ streamlit run example.py -- -m Sekai
666
+ ```
667
+
668
+ ## Click
669
+ ```
670
+ 続いてサードパーティ製のパッケージである Click を使う場合。
671
+ Click は純粋なコマンドラインパーサ以外の機能もあることから、スクリプトを記述する時点から注意点がある。
672
+ 具体的には、デコレータで修飾したオブジェクトを呼び出すときに standalone_mode を False に指定する。
673
+ こうすると、デフォルトでは実行が完了したときに exit() してしまう振る舞いを抑制できる。
674
+ ```
675
+
676
+ ```
677
+ # -*- coding: utf-8 -*-
678
+
679
+ import streamlit as st
680
+ import click
681
+
682
+
683
+ @click.command()
684
+ @click.option('--message', '-m', type=str, default='World')
685
+ def main(message):
686
+ # パースした引数を表示する
687
+ st.write(f'Hello, {message}!')
688
+
689
+
690
+ if __name__ == '__main__':
691
+ # click.BaseCommand.main() メソッドが呼ばれる
692
+ # デフォルトの動作では返り値を戻さずに exit してしまう
693
+ # スタンドアロンモードを無効にすることで純粋なコマンドラインパーサとして動作する
694
+ main(standalone_mode=False)
695
+ ```
696
+
697
+ ```
698
+ $ streamlit run example.py -- -m Sekai
699
+ ```
700
+
701
+
702
+ # 【Streamlit】株価データのお手軽GUI分析
703
+ [ 【Streamlit】株価データのお手軽GUI分析 2021-03-20] ( https://dajiro.com/entry/2021/03/20/171130 )
704
+ <img src =" https://cdn-ak.f.st-hatena.com/images/fotolife/D/Dajiro/20210320/20210320160918.png " width =" 700 " height =" 500 " >
705
+
706
+
707
+ # cdsdashboards
708
+ [ ideonate/cdsdashboards] ( https://github.com/ideonate/cdsdashboards/tree/master/examples/sample-source-code/streamlit )
709
+
710
+
391
711
# Streamlit Offical API
392
712
[ Streamlit Offical API] ( https://share.streamlit.io/daniellewisdl/streamlit-cheat-sheet/app.py )
393
713
@@ -431,3 +751,4 @@ bodyの場合はst.コンポーネント名、サイドバーにの場合、st.s
431
751
- 2
432
752
- 3
433
753
754
+
0 commit comments