7
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Pythonのコードがそのままwebアプリになる『Streamlit』を試してみた

Posted at

公式サイト: https://www.streamlit.io/

データサイエンティストや機械学習エンジニアが、数時間で美しくて良いパフォーマンスのアプリを作成する一番簡単な方法だそうです。

単純に面白そうなのでやってみました。


参考にした記事



できたもの

動いてるところを動画にしました。

サイコロをいくつか振った時の平均値のグラフがサイコロの数を増やすと正規分布に近くという中心極限定理のデモアプリです。



このアプリを試したい方へ

Gistでソースコードを公開しているので、Streamlitをインストールすれば誰でも手元で実行できます。

インストール方法

pip streamlit

実行方法

streamlit run https://gist.githubusercontent.com/kokuyokugetter/1a7ec1243f469be03fa4574c05bf5018/raw/a49ca69a2f33a9945602caddd607898e2bf0b0ac/clt_demo_dice.py

要するにstreamlit run の後にソースコードを食わせれば良いっぽいです。gistは上げたコードのRawデータのページを呼び出せるので、ソースをダウンロードしなくてもリンクから実行可能です。


色々試しながら書いてたのを消すのもアレだったので、試行錯誤の部分や参考サイトのコードがそのまま載っていたりしますが、ソースコードのコメント部分(特に前半)は気にしないでください。

numpy.histogramとstreamlit.barchartで最初やってたら、グラフがめちゃくちゃになったのでやめたのもソースから伺えます。

整数値とnumpy.histogramが相性悪いのか、streamlit.barchartが相性悪いのかよくわからん。





感想

変数をスライダーで変えながらグラフに描画できるので、jupyterとかでいちいち変数の値を変えて再度実行とするより効果的な場面は出てきそうです。

7
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?