Exemple #1
0
def make_app(**kwargs):
    T = sc.tic()
    app = sw.ScirisApp(
        name='HealthPrior',
        filepath=__file__,
        config=hp.webapp.config,
        RPC_dict=hp.webapp.rpcs.RPC_dict
    )  # Create the ScirisApp object.  NOTE: app.config will thereafter contain all of the configuration parameters, including for Flask.
    sw.make_default_users(app)
    print('>> Webapp initialization complete (elapsed time: %0.2f s)' %
          sc.toc(T, output=True))
    return app
Exemple #2
0
import os
import sys
import numpy as np
import plotly.graph_objects as go
import plotly.figure_factory as ff
import sciris as sc
import base64 # Download/upload-specific import
import json
import tempfile

# Check requirements, and if met, import scirisweb
cv.requirements.check_scirisweb(die=True)
import scirisweb as sw

# Create the app
app = sw.ScirisApp(__name__, name="Covasim")
app.sessions = dict() # For storing user data
flask_app = app.flask_app

#%% Define the API

# Set defaults
max_pop  = 10e3 # Maximum population size
max_days = 180  # Maximum number of days
max_time = 10   # Maximum of seconds for a run
die      = False # Whether or not to raise exceptions instead of continuing

@app.register_RPC()
def get_defaults(region=None, merge=False):
    ''' Get parameter defaults '''
Exemple #3
0
# Imports
import pylab as pl
import sciris as sc
import scirisweb as sw
from dask.distributed import Client


client = Client()

runserver = False # Choose to run in the frontend or backend

# Create the app
app = sw.ScirisApp(__name__, name="ParallelComputation")

#def 

# Define the RPCs
@app.register_RPC()
def computation(seed=0, n=1000):
    
    # Make graph
    pl.seed(int(seed))
    fig = pl.figure()
    ax = fig.add_subplot(111)
    xdata = pl.randn(n)
    ydata = pl.randn(n)
    colors = sc.vectocolor(pl.sqrt(xdata**2+ydata**2))
    ax.scatter(xdata, ydata, c=colors)
    
    # Convert to FE
    graphjson = sw.mpld3ify(fig, jsonify=False)  # Convert to dict
Exemple #4
0
    rawdata = sc.wget(dataurl).splitlines()
    data = []
    for r,rawline in enumerate(rawdata):
        line = rawline.split(',')
        if r==0: # Read header
            cols = line
        else: # Read data
            tag = line[0]
            yearnum = convertdate(line[1], '%Y-%m-%dT%I:%M:%fZ')
            value = float(line[2]) if r>0 else line[2]
            data.append([tag, yearnum, value])
    df = sc.dataframe(cols=cols, data=data)
    return df

# Create the app
app = sw.ScirisApp(__name__, name="PyShiny")
df = loaddata()

# Define the RPCs
@app.register_RPC()
def getoptions(tojson=True):
    options = sc.odict([
        ('Advertising',    'advert'),
        ('Education',      'educat'),
        ('Small business', 'smallbiz'),
        ('Travel',         'travel'),
        ('Unemployment',   'unempl'),
        ])
    if tojson:
        output = sc.sanitizejson(options.keys(), tostring=False)
    else:
Exemple #5
0
Super simple Sciris app.

To run, simply type

   python app.py

after ScirisWeb has been installed.

To use, go to localhost:8080 in your browser.

Version: 2019jan12
'''

import pylab as pl
import scirisweb as sw
app = sw.ScirisApp(__name__, name="helloworld")


@app.route("/")
def hello():
    output = 'Hello world!<br><br>Click <a href="/number">here</a> for a random number.'
    return output


@app.route("/number")
def number():
    number = pl.rand()
    output = 'Random number: %s.<br><br>Click <a href="/">here</a> to go back.' % number
    return output