Coder Social home page Coder Social logo

st.file_uploader's Introduction

st.file_uploader

st.file_uploader displays a file uploader widget [1].

By default, uploaded files are limited to 200MB. You can configure this using the server.maxUploadSize config option. For more info on how to set config options, see [2].

Demo app

Streamlit App

Code

Here's how to use st.file_uploader:

import streamlit as st
import pandas as pd

st.title('st.file_uploader')

st.subheader('Input CSV')
uploaded_file = st.file_uploader("Choose a file")

if uploaded_file is not None:
  df = pd.read_csv(uploaded_file)
  st.subheader('DataFrame')
  st.write(df)
  st.subheader('Descriptive Statistics')
  st.write(df.describe())
else:
  st.info('☝️ Upload a CSV file')

Line-by-line explanation

The very first thing to do when creating a Streamlit app is to start by importing the streamlit library as st and other prerequisite library like so:

import streamlit as st
import pandas as pd

This is followed by creating a title text for the app:

st.title('st.file_uploader')

Next, we'll use st.file_uploader to display a file uploader widget for accepting user input file:

st.subheader('Input CSV')
uploaded_file = st.file_uploader("Choose a file")

Finally, we define conditional statements for initially displaying a welcome message inviting users to upload their file (as implemented in the else condition). Upon file upload, the if statements are activated and the CSV file is read by the pandas library and displayed via the st.write command.

if uploaded_file is not None:
  df = pd.read_csv(uploaded_file)
  st.subheader('DataFrame')
  st.write(df)
  st.subheader('Descriptive Statistics')
  st.write(df.describe())
else:
  st.info('☝️ Upload a CSV file')

Further reading

  1. st.file_uploader
  2. Set configuration options

st.file_uploader's People

Contributors

dataprofessor avatar gauravkoradiya avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.