awacke1 commited on
Commit
d4ac004
·
1 Parent(s): fdefbdd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +213 -84
app.py CHANGED
@@ -1,91 +1,220 @@
1
- import streamlit as st
2
  import pydeck as pdk
3
- import numpy as np
4
 
5
- # Define a data set
6
- data = np.random.randn(1000, 2) * 0.1
7
- layer = pdk.Layer(
8
- "ScatterplotLayer",
9
- data=data,
10
- get_position="[0, 1]",
11
- get_color="[200, 30, 0, 160]",
12
- get_radius=50,
13
- )
14
-
15
- # Define a Pydeck view state
16
- view_state = pdk.ViewState(latitude=37.7749, longitude=-122.4194, zoom=11)
17
-
18
- # Define Pydeck initial rendering options
19
- initial_options = pdk.Deck(
20
- map_style="mapbox://styles/mapbox/dark-v9",
21
- layers=[layer],
22
- initial_view_state=view_state,
23
- )
24
-
25
- # Define the HTML template for the Three.js canvas
26
- html_template = """
27
- <div id="three-canvas-container"></div>
28
- <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
29
- <script>
30
- var canvasContainer = document.getElementById("three-canvas-container");
31
-
32
- var camera = new THREE.PerspectiveCamera(70, window.innerWidth / window.innerHeight, 0.1, 1000);
33
- camera.position.z = 5;
34
-
35
- var renderer = new THREE.WebGLRenderer({antialias: true});
36
- renderer.setSize(window.innerWidth, window.innerHeight);
37
- canvasContainer.appendChild(renderer.domElement);
38
-
39
- var geometry = new THREE.BoxGeometry(1, 1, 1);
40
- var material = new THREE.MeshBasicMaterial({color: 0x00ff00});
41
- var cube = new THREE.Mesh(geometry, material);
42
- scene.add(cube);
43
-
44
- function animate() {
45
- requestAnimationFrame(animate);
46
- cube.rotation.x += 0.01;
47
- cube.rotation.y += 0.01;
48
- renderer.render(scene, camera);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  }
 
 
 
50
 
51
- animate();
52
- </script>
53
- """
54
-
55
- # Define the Streamlit app
56
- def app():
57
- # Define a Pydeck map using a ScatterplotLayer
58
- st.pydeck_chart(initial_options)
59
-
60
- # Add a dropdown menu to select Pydeck layer types
61
- layer_type = st.selectbox("Layer type", ["HexagonLayer", "HeatmapLayer", "ScatterplotLayer"])
62
-
63
- # Add sliders to adjust the Pydeck layer properties
64
- if layer_type == "HexagonLayer":
65
- layer.radius = st.slider("Radius", 10, 100, 50)
66
- layer.elevation_scale = st.slider("Elevation scale", 0, 10, 1)
67
- layer.elevation_range = st.slider("Elevation range", 0, 1000, 100)
68
- layer.pickable = st.checkbox("Pickable", True)
69
- layer.auto_highlight = st.checkbox("Auto highlight", True)
70
- elif layer_type == "HeatmapLayer":
71
- layer.intensity = st.slider("Intensity", 0, 10, 1)
72
- layer.radius = st.slider("Radius", 10, 100, 50)
73
- layer.color_range = st.color_picker("Color range", ["#008000", "#FFFF00", "#FF0000"])
74
- layer.opacity = st.slider("Opacity", 0, 1, 0.8)
75
- layer.blend_mode = st.selectbox("Blend mode", ["additive", "multiply"])
76
- elif layer_type == "ScatterplotLayer":
77
- layer.get_position = "[0, 1, 2]"
78
- layer.get_color = "[200, 30, 0, 160]"
79
- layer.get_radius = st.slider("Radius", 10, 100, 50)
80
-
81
- # Add the updated Pydeck layer to the map
82
- #st.pydeck_chart(pdk.Deck(layers=[layer], initial_view_state=view_state))
83
- st.pydeck_chart(pdk.Deck(layers=[layer]))
84
 
85
- # Add the Three.js canvas to the Streamlit app
86
- st.components.v1.html(html_template, height=500)
 
 
 
 
 
 
 
 
 
87
 
88
- if name == "main":
89
- app()
90
 
91
- # This app has a Pydeck map that displays a scatterplot layer by default, and it allows the user to switch between HexagonLayer, HeatmapLayer, and ScatterplotLayer using a dropdown menu. The user can also adjust the properties of the selected layer using sliders and color pickers. Finally, the app displays a Three.js canvas that rotates a green cube.
 
1
+ import pandas as pd
2
  import pydeck as pdk
 
3
 
4
+ # Define the list of dictionaries with hospital information
5
+ hospital_list = [
6
+ {
7
+ 'bed_count': 2766,
8
+ 'name': 'New York-Presbyterian Hospital',
9
+ 'city': 'New York',
10
+ 'state': 'NY',
11
+ 'latitude': 40.8404,
12
+ 'longitude': -73.9508,
13
+ 'zip': '10032'
14
+ },
15
+ {
16
+ 'bed_count': 2145,
17
+ 'name': 'Florida Hospital Orlando',
18
+ 'city': 'Orlando',
19
+ 'state': 'FL',
20
+ 'latitude': 28.5536,
21
+ 'longitude': -81.3568,
22
+ 'zip': '32803'
23
+ },
24
+ {
25
+ 'bed_count': 2020,
26
+ 'name': 'Jackson Memorial Hospital',
27
+ 'city': 'Miami',
28
+ 'state': 'FL',
29
+ 'latitude': 25.7893,
30
+ 'longitude': -80.2124,
31
+ 'zip': '33136'
32
+ },
33
+ {
34
+ 'bed_count': 1997,
35
+ 'name': 'Keck Medical Center of USC',
36
+ 'city': 'Los Angeles',
37
+ 'state': 'CA',
38
+ 'latitude': 34.0522,
39
+ 'longitude': -118.2437,
40
+ 'zip': '90033'
41
+ },
42
+ {
43
+ 'bed_count': 1956,
44
+ 'name': 'Montefiore Medical Center',
45
+ 'city': 'Bronx',
46
+ 'state': 'NY',
47
+ 'latitude': 40.8471,
48
+ 'longitude': -73.8816,
49
+ 'zip': '10467'
50
+ },
51
+ {
52
+ 'bed_count': 1926,
53
+ 'name': 'Rush University Medical Center',
54
+ 'city': 'Chicago',
55
+ 'state': 'IL',
56
+ 'latitude': 41.8745,
57
+ 'longitude': -87.6676,
58
+ 'zip': '60612'
59
+ },
60
+ {
61
+ 'bed_count': 1918,
62
+ 'name': 'University of Michigan Hospitals-Michigan Medicine',
63
+ 'city': 'Ann Arbor',
64
+ 'state': 'MI',
65
+ 'latitude': 42.2814,
66
+ 'longitude': -83.7483,
67
+ 'zip': '48109'
68
+ },
69
+ {
70
+ 'bed_count': 1863,
71
+ 'name': 'Parkland Health and Hospital System',
72
+ 'city': 'Dallas',
73
+ 'state': 'TX',
74
+ 'latitude': 32.7767,
75
+ 'longitude': -96.7970,
76
+ 'zip': '75235'
77
+ },
78
+ {
79
+ 'bed_count': 1858,
80
+ 'name': 'Houston Methodist Hospital',
81
+ 'city': 'Houston',
82
+ 'state': 'TX',
83
+ 'latitude': 29.7181,
84
+ 'longitude': -95.4044,
85
+ 'zip': '77030'
86
+ },
87
+ {
88
+ 'bed_count': 1800,
89
+ 'name': 'Brigham and Women\'s Hospital',
90
+ 'city': 'Boston',
91
+ 'state': 'MA',
92
+ 'latitude': 42.3367,
93
+ 'longitude': -71.1075,
94
+ 'zip': '02115'
95
+ },
96
+ {
97
+ 'bed_count': 1771,
98
+ 'name': 'Cleveland Clinic',
99
+ 'city': 'Cleveland',
100
+ 'state': 'OH',
101
+ 'latitude': 41.5047, 'longitude': -81.6218,
102
+ 'zip': '44195'
103
+ },
104
+ {
105
+ 'bed_count': 1730,
106
+ 'name': 'The Mount Sinai Hospital',
107
+ 'city': 'New York',
108
+ 'state': 'NY',
109
+ 'latitude': 40.7909,
110
+ 'longitude': -73.9524,
111
+ 'zip': '10029'
112
+ },
113
+ {
114
+ 'bed_count': 1729,
115
+ 'name': 'Northwestern Memorial Hospital',
116
+ 'city': 'Chicago',
117
+ 'state': 'IL',
118
+ 'latitude': 41.8953,
119
+ 'longitude': -87.6251,
120
+ 'zip': '60611'
121
+ },
122
+ {
123
+ 'bed_count': 1660,
124
+ 'name': 'Hospitals of the University of Pennsylvania-Penn Presbyterian',
125
+ 'city': 'Philadelphia',
126
+ 'state': 'PA',
127
+ 'latitude': 39.9526,
128
+ 'longitude': -75.1652,
129
+ 'zip': '19104'
130
+ },
131
+ {
132
+ 'bed_count': 1642,
133
+ 'name': 'Johns Hopkins Hospital',
134
+ 'city': 'Baltimore',
135
+ 'state': 'MD',
136
+ 'latitude': 39.2967,
137
+ 'longitude': -76.5913,
138
+ 'zip': '21287'
139
+ },
140
+ {
141
+ 'bed_count': 1614,
142
+ 'name': 'Cedars-Sinai Medical Center',
143
+ 'city': 'Los Angeles',
144
+ 'state': 'CA',
145
+ 'latitude': 34.0762,
146
+ 'longitude': -118.3882,
147
+ 'zip': '90048'
148
+ },
149
+ {
150
+ 'bed_count': 1577,
151
+ 'name': 'Massachusetts General Hospital',
152
+ 'city': 'Boston',
153
+ 'state': 'MA',
154
+ 'latitude': 42.3639,
155
+ 'longitude': -71.0711,
156
+ 'zip': '02114'
157
+ },
158
+ {
159
+ 'bed_count': 1566,
160
+ 'name': 'NYU Langone Hospitals',
161
+ 'city': 'New York',
162
+ 'state': 'NY',
163
+ 'latitude': 40.7429,
164
+ 'longitude': -73.9750,
165
+ 'zip': '10016'
166
+ },
167
+ {
168
+ 'bed_count': 1547,
169
+ 'name': 'Mayo Clinic Hospital-Rochester',
170
+ 'city': 'Rochester',
171
+ 'state': 'MN',
172
+ 'latitude': 44.0121,
173
+ 'longitude': -92.4802,
174
+ 'zip': '55902'
175
+ },
176
+ {
177
+ 'bed_count': 1537,
178
+ 'name': 'Stanford Health Care-Stanford Hospital',
179
+ 'city': 'Stanford',
180
+ 'state': 'CA',
181
+ 'latitude': 37.4354,
182
+ 'longitude': -122.1777,
183
+ 'zip': '94305'
184
  }
185
+ ]
186
+
187
+ df = pd.DataFrame(hospital_list)
188
 
189
+ layer = pdk.Layer(
190
+ 'ScatterplotLayer',
191
+ data=df,
192
+ get_position='[longitude, latitude]',
193
+ get_radius='bed_count/10',
194
+ get_fill_color='[bed_count, 0, 255-bed_count]',
195
+ get_line_color=[255, 255, 255],
196
+ pickable=True
197
+ )
198
+
199
+ tooltip = {
200
+ 'html': '<b>{name}</b><br/>{bed_count} beds<br/>{city}, {state} {zip}',
201
+ 'style': {
202
+ 'backgroundColor': 'white',
203
+ 'color': 'black'
204
+ }
205
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
206
 
207
+ map = pdk.Deck(
208
+ map_style='mapbox://styles/mapbox/light-v9',
209
+ initial_view_state=pdk.ViewState(
210
+ latitude=37.0902,
211
+ longitude=-95.7129,
212
+ zoom=3,
213
+ pitch=0
214
+ ),
215
+ layers=[layer],
216
+ tooltip=tooltip
217
+ )
218
 
 
 
219
 
220
+ map.show()