widgetti / widgetti/ipyvuetify

How to Create a Button for Downloading data

Open
#326 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
355
Forks
61
PR merge metrics
No merged PRs in 30d

Description

Hello team,

I am currently working on a project (on Jupyter Notebook Server) where I need to provide users with the ability to download pandas DataFrames as Excel or JSON files directly from a Jupyter Notebook using ipyvuetify buttons.

I have implemented a solution that uses base64 encoding to create download links, but I am looking for feedback or suggestions on best practices or alternative approaches that might be more efficient or aligned with ipyvuetify's capabilities.

Here is a simplified version of my current implementation:


import ipyvuetify as v
import pandas as pd
from io import BytesIO
import base64

# Sample DataFrame
df = pd.DataFrame({
    'A': [1, 2, 3],
    'B': [4, 5, 6]
})

def create_excel_download_link(df):
    output = BytesIO()
    df.to_excel(output, index=False)
    output.seek(0)
    b64 = base64.b64encode(output.getvalue()).decode()
    return f"data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,{b64}"

# Create download buttons
excel_output_button = v.Btn(
    children=[
        v.Icon(left=True, children=['mdi-file-excel']),
        'Download Output Excel'
    ],
    color='success',
    class_='ma-2'
)

excel_input_button = v.Btn(
    children=[
        v.Icon(left=True, children=['mdi-file-excel']),
        'Download Input Excel'
    ],
    color='success',
    class_='ma-2'
)

# Function to handle button click
def on_excel_button_click(button, df):
    button.href = create_excel_download_link(df)
    button.target = '_blank'
    button.download = 'data.xlsx'

# Attach event handlers
excel_input_button.on_event('click', lambda *args: on_excel_button_click(excel_input_button, df))
excel_output_button.on_event('click', lambda *args: on_excel_button_click(excel_output_button, df))

# Display buttons in a card
card = v.Card(
    children=[
        v.CardTitle(class_='headline', children=['Download Data']),
        v.CardText(children=[excel_input_button, excel_output_button])
    ]
)

Did you have an idea ?

Thank you,
Florian

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No repository files, tests, or entry points are mentioned. Begin by clarifying whether this is a request for an ipyvuetify capability or usage guidance; completion cannot be defined until the expected supported download behavior is agreed.

Written by the indexing model from the issue text.

Assessment

Tech stack
jupyter-notebook, pandas, python
Domain
frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.