Skip to content

Instantly share code, notes, and snippets.

@nockn
Created July 15, 2021 04:20
Show Gist options
  • Save nockn/95cdeeb9d3deece74b1e7fc72a2ee323 to your computer and use it in GitHub Desktop.
Save nockn/95cdeeb9d3deece74b1e7fc72a2ee323 to your computer and use it in GitHub Desktop.
[note] layout options for Streamlit
import streamlit as st
st.header("Streamlit Layout Demo")
st.subheader("beta_columns, beta_container")
# https://blog.streamlit.io/introducing-new-layout-options-for-streamlit/
st.markdown("---")
# レイアウトの宣言
# カラム(横方向に分割)
column_left, column_right = st.beta_columns([2, 1])
# コンテナ(箱。入れ子にしたり縦につなげられる)
container_top = column_left.beta_container()
container_middle = column_left.beta_container()
container_bottom = column_left.beta_container()
# 要素は with [オブジェクト]: または[オブジェクト].[関数]で配置
container_top.write("右のフォームに合わせて表示が変わります。")
column_right.write("入力フォーム")
with column_right:
c = st.number_input("A+B", 0, 100, step=1)
b = st.number_input("B", 0, 100, step=1)
with container_bottom:
st.write("A+B = %d" % c)
with container_middle:
st.write("B = %d" % b)
with container_top:
st.write("A = %d" % (c - b))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment