删除流式应用程序中的宽边距

问题描述 投票:0回答:1

我正在制作一个streamlit应用程序,但是我的图表的左侧和右侧有大量的空白区域。我想删除边距并水平放置一些图表。如何删除应用程序左侧和右侧的边距?我从我一直关注的教程中获得了此代码。

import streamlit as st
import pandas as pd
import matplotlib.pyplot as plt
import plotly_express as px

def stats(dataframe):
  st.header('Data Statistics')
  st.write(dataframe.describe())
  
def data_header(dataframe):
  st.header('Data Header')
  st.write(dataframe.head())
  
def plot(dataframe):
  fig, ax = plt.subplots(1,1)
  ax.scatter(x = dataframe['Depth'], y = dataframe['Magnitude'])
  ax.set_xlabel('Depth')
  ax.set_ylabel('Magnitude')
  st.pyplot(fig)
  
def interactive_plot(dataframe):
  x_axis_val = st.selectbox('Select x-axis attribute', options = df.columns)
  y_axis_val = st.selectbox('Select y-axis attribute', options = df.columns)
  col = st.color_picker('Select a plot color')
  
  plot = px.scatter(dataframe, x = x_axis_val, y = y_axis_val)
  plot.update_traces(marker = dict(color = col))
  st.plotly_chart(plot)

st.title('Earthquake Data Explorer')
st.text('This is a web app to explore earthquake data.')
# st.markdown('## This is **markdown**.')

st.sidebar.title('Navigation')
uploaded_file = st.sidebar.file_uploader('Upload your file here.')

options = st.sidebar.radio('Pages', options = ['Home', 'Data Statistics', 'Data Header', 'Plot', 'Interactive Plot'])

df = pd.read_csv('/Users/deisert/Documents/FAA-Sabin/Dashboard/kaggle_significant_earthquakes_database.csv')

if options == 'Data Statistics':
  stats(df)
elif options == 'Data Header':
  data_header(df)
elif options == 'Plot':
  plot(df)
elif options == 'Interactive Plot':
  interactive_plot(df)
python streamlit
1个回答
0
投票

使用

set_page_config
指定宽布局,删除左侧和右侧的空白。

import streamlit as st

st.set_page_config(
    layout="wide",
)
st.image("https://picsum.photos/2000/800")

它给出:

© www.soinside.com 2019 - 2024. All rights reserved.