Git Product home page Git Product logo

streamlit-lottie's Introduction

Streamlit Lottie

Streamlit App

Integrate Lottie animations inside your Streamlit app!

Install

pip install streamlit-lottie

Usage

  • Basic usage
import streamlit as st
from streamlit_lottie import st_lottie

with st.echo():
    st_lottie("https://assets5.lottiefiles.com/packages/lf20_V9t630.json")
  • Basic usage (with monkey patched st.lottie function)
import streamlit as st
import streamlit_lottie

with st.echo():
    st.lottie("https://assets5.lottiefiles.com/packages/lf20_V9t630.json")
  • Context manager usage, using with notation
import time

import streamlit as st
from streamlit_lottie import st_lottie

with st_lottie("https://assets5.lottiefiles.com/packages/lf20_V9t630.json"):
    time.sleep(5)
  • Download lottie manually example
import time
import requests

import streamlit as st
from streamlit_lottie import st_lottie
from streamlit_lottie import st_lottie_spinner


def load_lottieurl(url: str):
    r = requests.get(url)
    if r.status_code != 200:
        return None
    return r.json()


lottie_url_hello = "https://assets5.lottiefiles.com/packages/lf20_V9t630.json"
lottie_url_download = "https://assets4.lottiefiles.com/private_files/lf30_t26law.json"
lottie_hello = load_lottieurl(lottie_url_hello)
lottie_download = load_lottieurl(lottie_url_download)


st_lottie(lottie_hello, key="hello")

if st.button("Download"):
    with st_lottie_spinner(lottie_download, key="download"):
        time.sleep(5)
    st.balloons()

Development

Install

  • JS side
cd frontend
npm install
  • Python side
conda create -n streamlit-lottie python=3.7
conda activate streamlit-lottie
pip install -e .

Run

Both webpack dev server and Streamlit need to run for development mode.

  • JS side
cd frontend
npm run start
  • Python side
streamlit run app.py

References

Support me

Buy Me A Coffee

streamlit-lottie's People

Contributors

andfanilo avatar sfc-gh-tszerszen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

streamlit-lottie's Issues

Empty loaded animation.

Hi there,

Is there a way to empty loaded animation? Something like:

animation = st_lottie(loadLottieUrl([URL]))
...some operations
animation.empty()

Regards,
Don

Can we load locally?

I tried downloading the .json file from lottie and putting it into st.lottie("path/to/json") but it does nto work.

Position issue in streamlit multipage app

Hi, I'm trying to use lottie animation in streamlit multippage. But the issue is I cannot set the position of lottie logo. It's always at the bottom of menu pages. I tried to change the CSS but no success.

lottie

Is there a way to fix this? I need the logo on top of pages.

transparency?

ive been uploading and converting transparent gifs with lottiefiles and one of the gifs ive uploaded if i make a stremalit component and inject the script:

`

<script src="https://unpkg.com/@dotlottie/player-component@latest/dist/dotlottie-player.mjs" type="module"></script>
<dotlottie-player src="https://link-to-jottie.com/lottie.json" background="transparent" speed="1" style="width: 300px; height: 300px;" loop autoplay></dotlottie-player>

`

it allows you to set background="transparent" which ensures transparency, the only downside to this method is it only works on desktops and not mobile, whereas this component works anywhere streamlit works.. but when i load in the same lottie file this shows a black background.. is there anyway to work around that?

how to use lottie components as spinner

@andfanilo assume i want to show lottie animation as a spinner. how can i delete the lottie component after the task is finished?

sample code:

import time
import streamlit as st
from streamlit_lottie import st_lottie
import requests
def load_lottieurl(url: str):
    r = requests.get(url)
    if r.status_code != 200:
        return None
    return r.json()

lottie_url = "https://assets9.lottiefiles.com/packages/lf20_wvwimamz.json"
lottie_json = load_lottieurl(lottie_url)

with st.spinner(
        text="Downloading.. "
    ):
        st_lottie(lottie_json, height=150, key="loading_gif")
        time.sleep(5)

Then the animation does not stop when spinner is finished.

Align Center

I have tried changing the size of a lottie by reducing the original one. But it is aligned left.
Is there a way to align at the centre?
I tried looking at the code and it seem like one can only modify the height and width, but not the alignment.

Is it possible to add such a argument to the st_lottie_spinner?

Thank you in advance, Fanillo.

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.