Skip to content

Instantly share code, notes, and snippets.

@sinhrks
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sinhrks/6162d43d8272533d53d0 to your computer and use it in GitHub Desktop.
Save sinhrks/6162d43d8272533d53d0 to your computer and use it in GitHub Desktop.
spyre sample
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# https://github.com/adamhajari/spyre
from spyre import server
import numpy as np
import pandas as pd
pd.options.display.mpl_style = 'default'
import urllib2
import json
base = 'https://raw.githubusercontent.com/dichika/mydata/master/'
df1 = pd.read_csv(base + 'ore.csv')
df2 = pd.read_csv(base + 'ore_wt.csv')
df1['time'] = pd.to_datetime(df1['time'])
df2['time'] = pd.to_datetime(df2['time'])
df1 = df1.set_index('time')
df2 = df2.set_index('time')
df = df1.join(df2)
class OreExample(server.App):
title = u"ある人の歩数と体重"
inputs = [{ "input_type":'dropdown',
"label": 'Frequency',
"options" : [ {"label": "month", "value":"M"},
{"label": "week", "value":"W"},
{"label": "day", "value":"D"},],
"variable_name": 'freq',
"action_id": "update_data" }]
controls = [{ "control_type" : "hidden",
"label" : "update",
"control_id" : "update_data"}]
tabs = ["Plot", "Table"]
outputs = [{ "output_type" : "plot",
"output_id" : "plot",
"control_id" : "update_data",
"tab" : "Plot",
"on_page_load" : True },
{ "output_type" : "table",
"output_id" : "table_id",
"control_id" : "update_data",
"tab" : "Table",
"on_page_load" : True }]
def getData(self, params):
aggfuncs = {'weight': np.mean, 'steps': np.sum}
tmp = df.groupby(pd.TimeGrouper(params['freq'])).agg(aggfuncs)
return tmp
def getPlot(self, params):
df = self.getData(params)
ax = df.plot(secondary_y='weight')
return ax.get_figure()
app = OreExample()
app.launch(port=9093)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment