How to Embed Donation Forms & Buttons in Streamlit
Introduction
Creating a Streamlit app is exciting, and adding a donation button can enhance user engagement. It allows your supporters to contribute directly to your work. In this post, I’ll walk through several methods for integrating donation options into your Streamlit app. Let’s dive in!
Setting Up Your Donation Options
For collecting donations, I personally recommend two platforms: Buy Me a Coffee and Kofi. Both services allow users to support you through small donations, often represented as buying a coffee. Setting up an account on these platforms is straightforward, and I’ve provided links to both for your convenience.
Adding a Buy Me a Coffee Button
The easiest way to include a Buy Me a Coffee button in your app is by using the Streamlit Extra package. You can install it using:
pip install streamlit-extras
Once installed, you can import it and set up your button. Here’s how:
Input your username in the button setup, and you can enable a floating effect that keeps it visible as users scroll. Additionally, you can place the button in the sidebar, but be cautious of the white background issue if you choose that option.
Using Kofi for Donations
Another option is Kofi, which I prefer since it does not charge a transaction fee, unlike Buy Me a Coffee, which has a 5% fee. To implement a Kofi button, log into your Kofi account, navigate to the buttons section, and select either an image or a JavaScript button. Copy the code provided and paste it into your Streamlit app, ensuring you allow HTML.
Embedding a Donation Form Directly in Streamlit
The last method, and perhaps the most engaging, is embedding a donation form directly within your Streamlit app. This allows visitors to donate without leaving your site.
To do this, navigate to Kofi’s donation widget and copy the source URL from the iframe provided. In your Streamlit app, use the iframe component and set the height to 800 pixels. This will display the donation form directly in your app.
Conclusion
Integrating donation options into your Streamlit app can significantly enhance user interaction and support. Whether you opt for buttons from Buy Me a Coffee or Kofi, or choose to embed a donation form directly, these methods allow you to collect donations effectively. I hope this guide helps you set up your donation features smoothly!