Files

questions / element / fileDownload / server.py
Edit Download
import io

import matplotlib.pyplot as plt


def file(data):
    if data["filename"] == "data.txt":
        return "This data is generated by code."
    elif data["filename"] == "figure.png":
        plt.plot([1, 2, 3], [3, 4, -2])
        buf = io.BytesIO()
        plt.savefig(buf, format="png")
        return buf