Load on click

Load on click

We will load dataset on button click in this example. Data is loaded only when button is clicked.

Required packages

You will need pandas and mercury packages to run this example.


In the first cell, please import required packages:

import pandas as pd
import mercury as mr

Let's add Button widget:

load = mr.Button(label="Load data")

We will define variable to keep reference to dataset:

df = None

We will load data when button is clicked:

if load.clicked:
    df = pd.read_csv("https://raw.githubusercontent.com/pplonski/datasets-for-start/master/adult/data.csv")

We display data in the last cell:

df.head() if df is not None else print("Data not loaded")

The screenshot of the notebook's code in the Jupyter Notebook:

Python notebook with code for loading large dataset

Mercury App

Please start Mercury in the same directory as notebook:

mercury run

You will see the app running at Below is an animation with Mercury App.

Mercury App for loading large dataset