Skip to content

Commit 74ec324

Browse files
committed
Some airmass cleanup
1 parent 6a18e00 commit 74ec324

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

examples/airmass/app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@
3333
),
3434
ui.panel_well(
3535
ui.input_text_area(
36-
"objects", "Target object(s)", "Sirius, Betelgeuse, NGC35", rows=3
36+
"objects", "Target object(s)", "M1, NGC35, PLX299", rows=3
3737
),
3838
class_="pb-1 mb-3",
3939
),
4040
ui.panel_well(
41-
location_ui("location", lat=0, long=0),
41+
location_ui("location"),
4242
class_="mb-3",
4343
),
4444
class_="order-1 order-sm-2",

examples/airmass/location.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
def location_ui(
1414
label: str = "Location",
1515
*,
16-
lat: Optional[float],
17-
long: Optional[float],
16+
lat: Optional[float] = None,
17+
long: Optional[float] = None,
1818
) -> ui.TagChildArg:
1919
return ui.div(
20-
ui.input_numeric("lat", "Latitude", value=None),
21-
ui.input_numeric("long", "Longitude", value=None),
20+
ui.input_numeric("lat", "Latitude", value=lat),
21+
ui.input_numeric("long", "Longitude", value=long),
2222
ui.help_text("Click to select location"),
2323
output_widget("map", height="200px"),
2424
ui.tags.style(
@@ -39,9 +39,12 @@ def location_server(
3939
marker = L.Marker(location=(52, 100))
4040

4141
@reactive.Effect
42-
@reactive.isolate()
42+
@reactive.isolate() # Use this to ensure we only execute one time
4343
def _():
44-
if not input.lat() and not input.long():
44+
if input.lat() is None and input.long() is None:
45+
ui.notification_show(
46+
"Searching for location...", duration=False, id="searching"
47+
)
4548
ui.insert_ui(
4649
ui.tags.script(
4750
"""
@@ -51,7 +54,7 @@ def _():
5154
Shiny.setInputValue("#HERE#", {latitude, longitude});
5255
},
5356
(err) => {
54-
Shiny.setInputValue("#HERE#", null);
57+
Shiny.setInputValue("#HERE#", {latitude: 0, longitude: 0});
5558
},
5659
{maximumAge: Infinity, timeout: Infinity}
5760
)
@@ -90,6 +93,7 @@ def on_marker_move():
9093
@reactive.Effect
9194
def detect_location():
9295
coords = input.here()
96+
ui.notification_remove("searching")
9397
if coords and not input.lat() and not input.long():
9498
ui.update_numeric("lat", value=coords["latitude"])
9599
ui.update_numeric("long", value=coords["longitude"])
@@ -116,11 +120,17 @@ def sync_map_long():
116120

117121
@reactive.Calc
118122
def location():
123+
"""Returns tuple of (lat,long) floats--or throws silent error if no lat/long is
124+
selected"""
125+
126+
# Require lat/long to be populated before we can proceed
119127
req(input.lat() is not None, input.long() is not None)
120-
long = float(input.long())
121-
if wrap_long:
122-
long = (long + 180) % 360 - 180
128+
123129
try:
130+
long = float(input.long())
131+
# Wrap longitudes so they're within [-180, 180]
132+
if wrap_long:
133+
long = (long + 180) % 360 - 180
124134
return (float(input.lat()), long)
125135
except ValueError:
126136
raise ValueError("Invalid latitude/longitude specification")

0 commit comments

Comments
 (0)