Skip to content

Commit dfbe6ec

Browse files
committed
Update for Tethys Platform 3.0 Release
1 parent 8bd775e commit dfbe6ec

File tree

7 files changed

+91
-98
lines changed

7 files changed

+91
-98
lines changed

install.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@ requirements:
99
conda:
1010
channels:
1111
- conda-forge
12-
- bokeh/label/dev
1312
packages:
14-
- bokeh>=1.3.5*
15-
- param
1613
- panel
14+
- param
1715

1816
pip:
1917

tethysapp/bokeh_tutorial/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ def url_maps(self):
4040
),
4141
)
4242

43-
return url_maps
43+
return url_maps
Lines changed: 15 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1+
from bokeh.embed import server_document
2+
from bokeh.layouts import column
3+
from bokeh.models import ColumnDataSource, Slider
4+
from bokeh.plotting import figure
5+
from bokeh.sampledata.sea_surface_temperature import sea_surface_temperature
16
from django.shortcuts import render
7+
import panel as pn
28
from tethys_sdk.permissions import login_required
9+
from tethys_sdk.gizmos import Button
10+
from .param_model import ShapeViewer
311

4-
from bokeh.plotting import figure
5-
from bokeh.models import ColumnDataSource, Slider
6-
from bokeh.layouts import column
7-
from bokeh.sampledata.sea_surface_temperature import sea_surface_temperature
8-
from bokeh.embed import server_document
912

10-
import param
11-
import panel as pn
12-
import numpy as np
13+
@login_required()
14+
def home(request):
15+
script = server_document(request.build_absolute_uri())
16+
context = {'script': script}
17+
return render(request, 'bokeh_tutorial/home.html', context)
1318

1419

1520
def home_handler(document):
@@ -33,80 +38,14 @@ def callback(attr, old, new):
3338

3439
document.add_root(column(slider, plot))
3540

36-
3741
@login_required()
38-
def home(request):
42+
def shapes_with_panel(request):
3943
script = server_document(request.build_absolute_uri())
4044
context = {'script': script}
41-
return render(request, 'bokeh_tutorial/home.html', context)
42-
43-
44-
class Shape(param.Parameterized):
45-
radius = param.Number(default=1, bounds=(0, 1))
46-
47-
def __init__(self, **params):
48-
super(Shape, self).__init__(**params)
49-
self.figure = figure(x_range=(-1, 1), y_range=(-1, 1), width=500, height=500)
50-
self.renderer = self.figure.line(*self._get_coords())
51-
52-
def _get_coords(self):
53-
return [], []
54-
55-
def view(self):
56-
return self.figure
57-
58-
59-
class Circle(Shape):
60-
n = param.Integer(default=100, precedence=-1)
61-
62-
def __init__(self, **params):
63-
super(Circle, self).__init__(**params)
64-
65-
def _get_coords(self):
66-
angles = np.linspace(0, 2 * np.pi, self.n + 1)
67-
return (self.radius * np.sin(angles),
68-
self.radius * np.cos(angles))
69-
70-
@param.depends('radius', watch=True)
71-
def update(self):
72-
xs, ys = self._get_coords()
73-
self.renderer.data_source.data.update({'x': xs, 'y': ys})
74-
75-
76-
class NGon(Circle):
77-
n = param.Integer(default=3, bounds=(3, 10), precedence=1)
78-
79-
@param.depends('radius', 'n', watch=True)
80-
def update(self):
81-
xs, ys = self._get_coords()
82-
self.renderer.data_source.data.update({'x': xs, 'y': ys})
83-
84-
85-
shapes = [NGon(name='NGon'), Circle(name='Circle')]
86-
87-
88-
class ShapeViewer(param.Parameterized):
89-
shape = param.ObjectSelector(default=shapes[0], objects=shapes)
90-
91-
@param.depends('shape')
92-
def view(self):
93-
return self.shape.view()
94-
95-
@param.depends('shape', 'shape.radius')
96-
def title(self):
97-
return '## %s (radius=%.1f)' % (type(self.shape).__name__, self.shape.radius)
98-
99-
def panel(self):
100-
return pn.Column(self.title, self.view)
45+
return render(request, "bokeh_tutorial/shapes.html", context)
10146

10247

10348
def shapes_handler(document):
10449
viewer = ShapeViewer()
10550
panel = pn.Row(viewer.param, viewer.panel())
10651
panel.server_doc(document)
107-
108-
109-
def shapes_with_panel(request):
110-
script = server_document(request.build_absolute_uri())
111-
context = {'script': script}
112-
return render(request, "bokeh_tutorial/shapes.html", context)
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import param
2+
import panel as pn
3+
import numpy as np
4+
from bokeh.plotting import figure
5+
6+
7+
class Shape(param.Parameterized):
8+
radius = param.Number(default=1, bounds=(0, 1))
9+
10+
def __init__(self, **params):
11+
super(Shape, self).__init__(**params)
12+
self.figure = figure(x_range=(-1, 1), y_range=(-1, 1), width=500, height=500)
13+
self.renderer = self.figure.line(*self._get_coords())
14+
15+
def _get_coords(self):
16+
return [], []
17+
18+
def view(self):
19+
return self.figure
20+
21+
22+
class Circle(Shape):
23+
n = param.Integer(default=100, precedence=-1)
24+
25+
def __init__(self, **params):
26+
super(Circle, self).__init__(**params)
27+
28+
def _get_coords(self):
29+
angles = np.linspace(0, 2 * np.pi, self.n + 1)
30+
return (self.radius * np.sin(angles),
31+
self.radius * np.cos(angles))
32+
33+
@param.depends('radius', watch=True)
34+
def update(self):
35+
xs, ys = self._get_coords()
36+
self.renderer.data_source.data.update({'x': xs, 'y': ys})
37+
38+
39+
class NGon(Circle):
40+
n = param.Integer(default=3, bounds=(3, 10), precedence=1)
41+
42+
@param.depends('radius', 'n', watch=True)
43+
def update(self):
44+
xs, ys = self._get_coords()
45+
self.renderer.data_source.data.update({'x': xs, 'y': ys})
46+
47+
48+
shapes = [NGon(name='NGon'), Circle(name='Circle')]
49+
50+
51+
class ShapeViewer(param.Parameterized):
52+
shape = param.ObjectSelector(default=shapes[0], objects=shapes)
53+
54+
@param.depends('shape')
55+
def view(self):
56+
return self.shape.view()
57+
58+
@param.depends('shape', 'shape.radius')
59+
def title(self):
60+
return '## %s (radius=%.1f)' % (type(self.shape).__name__, self.shape.radius)
61+
62+
def panel(self):
63+
return pn.Column(self.title, self.view)

tethysapp/bokeh_tutorial/templates/bokeh_tutorial/base.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
{% block app_icon %}
88
{# The path you provided in your app.py is accessible through the tethys_app.icon context variable #}
9-
<img src="{% static tethys_app.icon %}">
9+
<img src="{% if 'http' in tethys_app.icon %}{{ tethys_app.icon }}{% else %}{% static tethys_app.icon %}{% endif %}" />
1010
{% endblock %}
1111

1212
{# The name you provided in your app.py is accessible through the tethys_app.name context variable #}

tethysapp/bokeh_tutorial/templates/bokeh_tutorial/home.html

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
{% extends "bokeh_tutorial/base.html" %}
22
{% load tethys_gizmos %}
33

4-
{% block header_buttons %}
5-
<div class="header-button glyphicon-button" data-toggle="tooltip" data-placement="bottom" title="Help">
6-
<a data-toggle="modal" data-target="#help-modal"><span class="glyphicon glyphicon-question-sign"></span></a>
7-
</div>
8-
{% endblock %}
9-
104
{% block app_content %}
115
<h1>Bokeh Integration Example</h1>
126
{{ script|safe }}

tethysapp/bokeh_tutorial/tests/tests.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,16 @@
1818
To run any tests:
1919
1. Open a terminal
2020
2. Enter command ". /usr/lib/tethys/bin/activate" to activate the Tethys python environment
21-
3. In settings.py make sure that the tethys_default database user is set to tethys_super
22-
DATABASES = {
23-
'default': {
24-
'ENGINE': 'django.db.backends.postgresql_psycopg2',
25-
'NAME': 'tethys_default',
26-
'USER': 'tethys_super',
27-
'PASSWORD': 'pass',
28-
'HOST': '127.0.0.1',
29-
'PORT': '5435'
30-
}
31-
}
21+
3. In portal_config.yml make sure that the default database user is set to tethys_super or is a super user of the database
22+
DATABASES:
23+
default:
24+
ENGINE: django.db.backends.postgresql_psycopg2
25+
NAME: tethys_platform
26+
USER: tethys_super
27+
PASSWORD: pass
28+
HOST: 127.0.0.1
29+
PORT: 5435
30+
3231
4. Enter tethys test command.
3332
The general form is: "tethys test -f tethys_apps.tethysapp.<app_name>.<folder_name>.<file_name>.<class_name>.<function_name>"
3433
See below for specific examples

0 commit comments

Comments
 (0)