• Stars
    star
    251
  • Rank 155,850 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 10 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Creating interactive visualizations with Python

gleam

Gleam lets you build interactive web visualizations of data using Python: no knowledge of HTML or JS necessary! You can choose a number of inputs your users can control, then use any Python graphing library to create plots based on those inputs. Gleam puts it all together creates a web interface that lets anyone play with your data in real time. Now it's easier than ever to help others understand and interpret your data. Gleam was inspired by the Shiny package in R.

See here for a live demo! (You can find the code for the demo in examples/baseball.py).

Example

Let's make an interactive visualization of a scatter plot. Here we'll have three inputs that can be controlled by the user:

  • The plot's title
  • What variable goes on the y axis
  • Whether we add a smoothing curve to the data

Start by importing a few packages. Gleam uses the wtforms package to provide form inputs. You can use any Python graphing package you want with Gleam, such as matplotlib, but we recommend the intuitive ggplot.

from wtforms import fields
from ggplot import *

Then import what you'll need from the gleam package:

from gleam import Page, panels

Inputs

An Inputs panel lets you specify the inputs that the user can control. Here, we add a string input for the title, a multiple choice select field for the Y-axis variable, and a checkbox for the smoother:

class ScatterInput(panels.Inputs):
    title = fields.StringField(label="Title of plot:")
    yvar = fields.SelectField(label="Y axis",
                              choices=[("beef", "Beef"),
                                       ("pork", "Pork")])
    smoother = fields.BooleanField(label="Smoothing Curve")

Output

The output is where your actual plotting goes. It comes in the form of a plot method, which takes an argument inputs containing the inputs from above. Here we use ggplot to make the plot, taking the arguments into consideration. (You could use any Python graphing packages in this function- the sky's the limit, as long as it creates a plot).

class ScatterPlot(panels.Plot):
    name = "Scatter"

    def plot(self, inputs):
        p = ggplot(meat, aes(x='date', y=inputs.yvar))
        if inputs.smoother:
            p = p + stat_smooth(color="blue")
        p = p + geom_point() + ggtitle(inputs.title)
        return p

Tying it together in a Page

Constructing an HTML page to allow this control is as simple as combining the input and the output:

class ScatterPage(Page):
    input = ScatterInput()
    output = ScatterPlot()

Run the app

You can then run the app with:

 ScatterPage.run()

By default, it will create a local server hosted at http://127.0.0.1:5000/: you can visit it there to see your cool visualization, which will look something like this:

plot

Try changing the title, the Y axis selector, or try checking the box: you'll see the plot react in real time.

You can add more inputs to the ScatterInput class, and then use them to further customize the plot in the ScatterPlot class.

Enjoy!

More Repositories

1

tidy-text-mining

Manuscript of the book "Tidy Text Mining with R" by Julia Silge and David Robinson
TeX
1,288
star
2

fuzzyjoin

Join tables together on inexact matching
R
656
star
3

data-screencasts

Code from live exploratory analyses of data in R
R
375
star
4

dgrtwo.github.com

My website
HTML
237
star
5

empirical-bayes-book

Introduction to Empirical Bayes: Examples from Baseball Statistics
TeX
186
star
6

StackLite

A simple dataset of Stack Overflow questions and tags
R
108
star
7

snippr

Manage, share, and install RStudio code snippets
R
78
star
8

ebbr

Empirical Bayes binomial estimation
R
69
star
9

stackr

R package for connecting to the Stack Exchange API
R
65
star
10

drlib

Personal R package
R
63
star
11

unvotes

United Nations General Assembly Voting Data
R
59
star
12

rpanama

The Panama Papers offshore leaks database in R
R
54
star
13

tabs-spaces-post

Code source behind the blog post "Developers who use spaces make more money than those who use tabs"
46
star
14

tracestack

Search Stack Overflow for your most recent error message
R
42
star
15

cranview

A Shiny app to visualize downloads from RStudio's CRAN mirror
R
34
star
16

knowledgerepo

R Interface to AirBnb's Knowledge Repository
R
28
star
17

splittestr

Functions for Bayesian A/B Testing Post
R
24
star
18

stacksurveyr

Stack Overflow 2016 Developer Survey Results
R
20
star
19

cord19

COVID-19 Open Research Dataset (work in progress)
R
20
star
20

adventdrob

Personal R package for Advent of Code
R
19
star
21

RData

Data Analysis and Visualization Using R: Course website
CSS
19
star
22

monetizr

Make money from your open source packages
R
18
star
23

love-actually-network

A Shiny app of "Love, Actually" connections
R
18
star
24

so-trends

Stack Overflow Trends
R
18
star
25

ggfreehand

Add freehand circles to ggplot2 graphs
R
17
star
26

rgallery

Build a gallery of R snippets
R
12
star
27

GSEAMA

Gene Set Enrichment Analysis Made Awesome
R
10
star
28

OASIS

Optimized Annotation System for Insertion Sequences
Python
10
star
29

adblockr

Block ads from the monetizr package
R
6
star
30

parsetidy

Tidy an R parse tree into a data frame
R
6
star
31

snippets

Example RStudio Snippets
5
star
32

BarNone

Match barcodes in sequencing data based on Levenshtein distance
C++
5
star
33

HW-Formatter

Formats homework assignments downloaded from Blackboard. Combines multiple PDFs and code files into a single PDF, while allowing syntax highlighting..
Python
4
star
34

providence-viewer

Visualize your programming style based Stack Exchange's Providence predictions
R
4
star
35

broom-gallery

Gallery of simple examples of the broom package, built with rgallery
CSS
4
star
36

Sweave2knitr

Convert Sweave LaTeX documents to work with knitr.
Python
4
star
37

serial-ggvis

A visualization of the call log and map from the Serial podcast, using ggvis and Shiny.
R
3
star
38

broom_paper

Manuscript of "broom: An R Package for Converting Statistical Analysis Objects Into Tidy Data Frames"
TeX
3
star
39

stackbigquery

Database-specific package for the Stack Overflow data on Google BigQuery
R
2
star
40

BarSeqG3

Reproduction information for "Design and Analysis of Bar-Seq Experiments"
R
2
star
41

rparse

Parse API Client for R
R
2
star
42

rgallery-default

Default gallery setup for the rgallery package
CSS
1
star
43

nofalThesis

Shared thesis functions
R
1
star