Skip to main content

dash-gif-component

dash-gif-component provides a playable gif dash component that is built on top of react-gif-player.

Plotly's dash documentation can be found here.

Background

While there may be many possible use cases for using a gif in a dash app, the one reason that originally inspired me to add them was to provide a visual aid to show end-users how to use various interactive features.

My original approach was to simply put a gif in an html <img> tag, but I quickly found out that this didn't work well in practice since the constant looping was a bit overwhelming, especially when there were multiple gifs on the same page.

The second approach was a bit more refined, and I wrote a plotly community blog post about it here. This used custom javascript that was dispatched when the window location's hash was changed and it worked just fine...that was until I learned that this caused very strange behavior in Internet Explorer when using dash > 0.39. There were also many other annoying issues when making this compatible with IE which made this a pain to maintain.

That brings me to dash-gif-component -- the final chapter of this story. Finally, a simple to use python module that wont require you to write a single line of javascript or create any hacks. It works on the latest version of dash, and best of all, works in IE as is!

Hope you enjoy using this plugin.

Installation

You can install dash-gif-component with pip:

pip install dash-gif-component

Documentation

dash-gif-comonent has only one component (GifPlayer) and it is really easy to setup. All you need to provide are two properties:

  1. gif: A string path to your gif
  2. still: A string path to an image that is used for the "pause" mode*
  3. There is also an optional property called autoplay which when set to true, will cause the gifs to automatically play. I find this to defeat the purpose of the component, but decided to include this for completeness when replicating react-gif-player.

*Gifsicle is a useful cli-tool that can extract the first, or any, frame of a gif, among other gif related tasks.

Note: if using local files for gif and still, then they must be loaded from the folder that is configured to serve static files. By default, this is set to assets.

Usage example:

import dash_gif_component as Gif
import dash
import dash_html_components as html

app = dash.Dash(__name__)

app.layout = html.Div([
    Gif.GifPlayer(
        gif='assets/my-gif.gif',
        still='assets/my-still.png',
    )
])

For a complete running example, please check out demo/usage.py

Custom Styling

While I do find the original style sheet to be excellent on its own, you may still want to make some tweaks here and there. There are only a handful of selectors and overwriting is straightforward. The stylesheet can be referenced in src/lib/components/css/gifplayer.css.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dash-gif-component-1.0.0.tar.gz (73.1 kB view details)

Uploaded Source

File details

Details for the file dash-gif-component-1.0.0.tar.gz.

File metadata

  • Download URL: dash-gif-component-1.0.0.tar.gz
  • Upload date:
  • Size: 73.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

File hashes

Hashes for dash-gif-component-1.0.0.tar.gz
Algorithm Hash digest
SHA256 19e19a80a3ee6d5c8df53b190c7196fe3a705f841f397082135d98f028fcce7f
MD5 22085b990f763fb9f1871d2fa623ba02
BLAKE2b-256 3d1180585467c9e5a5e0b1e4ec92f6c0457878b0c720292f46fc499dc921b9f2

See more details on using hashes here.

Release history Release notifications | RSS feed

1.1.0

1 file

1.0.2

1 file

1.0.1

1 file

This release

1.0.0 This release

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page