imgw / ui.R
alexdum's picture
Fix Monthly resolution date-range clamping and observer race
b16e88e
Raw History Blame Contribute Delete
6.83 kB
# ui.R
ui <- page_navbar(
id = "main_nav",
header = tagList(
shinyjs::useShinyjs(),
tags$head(
# Include external CSS and JS from www/ folder
tags$link(rel = "stylesheet", type = "text/css", href = "styles.css"),
tags$script(src = "app.js"),
# Style for shinyWidgets radioGroupButtons
tags$style(HTML("
.btn-group-container-sw .btn {
font-size: 0.85rem !important;
padding: 0.25rem 0.5rem !important;
}
.btn-group-container-sw .btn.active {
box-shadow: 0 0 0 3px rgba(13,110,253,0.4) !important;
font-weight: 700 !important;
filter: brightness(0.9);
}
")),
# Layer Control Interactions
tags$script(HTML("
$(document).ready(function() {
// Layer Control Interactions
var $layerControl = $('.map-layer-control');
$layerControl.on('mouseenter', function() {
$(this).addClass('expanded');
});
$layerControl.on('mouseleave', function() {
$(this).removeClass('expanded');
});
// Auto-close when a radio button (basemap) is selected
$layerControl.on('change', 'input[type=\\'radio\\']', function() {
$layerControl.removeClass('expanded');
});
});
"))
),
# Frozen overlay div
div(
class = "frozen-overlay",
div(
class = "frozen-overlay-content",
tags$button(class = "frozen-overlay-close", "×", title = "Cancel loading"),
p(class = "frozen-overlay-station", ""),
div(class = "spinner-border text-primary", role = "status"),
p(class = "frozen-overlay-message", "Loading data...")
)
)
),
title = "IMGW Explorer",
theme = bs_theme(version = 5, bootswatch = "cosmo"),
sidebar = sidebar(
title = "Filters",
# Station Count
textOutput("station_count"),
# Voivodeship / Region Filter
selectizeInput(
"county_filter",
label = span("Voivodeship / Region", tooltip(bsicons::bs_icon("info-circle"), "Filter meteorological stations by Polish Voivodeship (Wojew\u00f3dztwo).")),
choices = c(
"All Voivodeships" = "All",
setNames(
sort(imgw_voivodeship_catalog$voivodeship),
sort(imgw_voivodeship_catalog$voivodeship)
)
),
selected = "All",
multiple = FALSE
),
# Station Search
selectizeInput("station_selector", label = span("Find Station", tooltip(bsicons::bs_icon("info-circle"), "Search for a specific meteorological station by name.")), choices = NULL, multiple = FALSE, options = list(placeholder = "Type to search...")),
conditionalPanel(
condition = "input.station_selector && input.station_selector.length > 0 && input.station_selector !== '' && input.station_selector !== 'All'",
div(
class = "mt-1 mb-2",
actionButton(
"clear_station_sidebar",
label = span(bsicons::bs_icon("x-circle-fill", class = "me-1"), "Deselect Station"),
class = "sidebar-station-clear-btn"
)
)
),
div(
radioGroupButtons(
inputId = "temporal_resolution",
label = span("Temporal resolution", tooltip(bsicons::bs_icon("info-circle"), "Select the time interval for data aggregation (Hourly, Daily, or Monthly).")),
choices = c(
"Hourly" = "hourly",
"Daily" = "daily",
"Monthly" = "monthly"
),
selected = "daily",
status = "primary",
size = "sm"
)
),
dateRangeInput(
inputId = "date_range",
label = span("Date Range", tooltip(bsicons::bs_icon("info-circle"), "Choose the start and end dates. The maximum allowed span depends on the resolution (Hourly: 3 months, Daily: 1 year, Monthly: 6 years through the latest published IMGW monthly archive).")),
start = default_start_date,
end = default_end_date,
min = "1950-01-01",
max = default_end_date,
format = "yyyy-mm-dd",
separator = " to "
),
hr(),
p("Data source: IMGW-PIB (Poland)"),
p(style = "font-size: 0.8em; color: #666;", "Showing synoptic and climatological stations from klimat.imgw.pl metadata."),
hr(),
div(
style = "display: flex; align-items: flex-start; gap: 8px;",
tags$small("Tip: Click map points (or double-click table rows) to load the station dashboard.")
)
),
nav_panel(
title = "Map View",
value = "Map View",
div(
class = "outer",
maplibreOutput("map", height = "100%", width = "100%"),
# Floating Station Chip
absolutePanel(
id = "station_chip_panel",
top = 15, left = 60,
style = "z-index: 1000; pointer-events: none;",
uiOutput("station_chip_ui")
),
# Layer Control Panel (Collapsible) - Same position as DWD
absolutePanel(
top = 130, left = 10,
class = "map-layer-control",
style = "z-index: 1000;",
div(class = "control-icon", icon("layer-group")),
div(
class = "control-content",
radioButtons(
inputId = "basemap",
label = "Basemap",
choices = c(
"OpenFreeMap Positron" = "ofm_positron",
"OpenFreeMap Bright" = "ofm_bright",
"Satellite (Sentinel-2)" = "sentinel"
),
selected = "ofm_positron"
),
hr(style = "margin: 8px 0;"),
checkboxInput(
inputId = "show_labels",
label = "Show Labels",
value = TRUE
)
)
),
# Home Button Overlay - Same position as DWD
absolutePanel(
id = "zoom_home_panel",
top = 80, left = 10,
actionButton("zoom_home", bsicons::bs_icon("house-fill"), class = "btn-home", title = "Zoom to all stations")
)
)
),
nav_panel(
title = "Stations Info",
div(
style = "margin-bottom: 10px; color: #666; display: flex; align-items: center; gap: 6px;",
bsicons::bs_icon("info-circle"),
"Double-click a row to fetch station data and open the dashboard."
),
DT::dataTableOutput("stations_table")
),
nav_panel(
title = "Dashboard",
value = "Dashboard",
div(
class = "h-100 overflow-auto p-3",
uiOutput("dashboard_content")
)
),
nav_spacer(),
nav_item(
tooltip(
tags$a(
id = "fullscreen_toggle",
href = "#",
onclick = "toggleFullScreen(); return false;",
style = "display: flex; align-items: center; color: rgba(0,0,0,0.55); padding: 0.5rem 1rem; text-decoration: none;",
bsicons::bs_icon("arrows-fullscreen", size = "1.2rem")
),
"Toggle Fullscreen",
placement = "bottom"
)
)
)