Skip to content

PhilippVerpoort/piw

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DOI

Potsdam Interactive Webapp (PIW) framework library

Summary

This Python package can be used to host interactive webapps that make research available in an interactive and reusable way.

It is maintained and used at the Potsdam Institute for Climate Impact Research, a German research institute conducting integrated research for global sustainability.

How to use this library

This package can be added as a dependency:

poetry install git+https://github.com/PhilippVerpoort/piw.git # when using poetry
# OR
pipenv install git+https://github.com/PhilippVerpoort/piw.git # when using pipenv

You can then create a webapp via:

from piw import Webapp
from dash.dependencies import Input, State

webapp = Webapp(
    piw_id='my_webapp_id',
    load=[my_load_func],
    ctrls=[my_ctrl_func],
    generate_args=[
        Input('my-update-button', 'n_clicks'),
        State('my-parameter-table', 'data'),
    ],
    update=[my_update_func],
    proc=[my_process_func],
    plots=[MyFirstPlot, MySecondPlot],
)

The classes MyFirstPlot and MySecondPlot must be subclasses of piw.AbstractPlot. You can then export the figures into files via:

webapp.export()

You can also launch the webapp on your local machine via:

webapp.start()
webapp.run()

To host this webapp as a service with a WSGI-capable webserver (such as Apache2 with mod_wsgi), you need to create a file wsgi.py as such:

import sys, os
sys.path.insert(0,os.path.dirname(__file__))

from webapp import webapp

webapp.start()
application = webapp.flask_app

More details on hosting Flask apps with WSGI can be found here.

A more extensive tutorial on getting started with piw will soon be made available. Meanwhile, the following examples may serve as a starting point: