File size: 6,829 Bytes
3e1cf28
 
 
 
 
 
 
 
b4a8f62
2e9a2d0
 
 
 
 
 
 
 
 
 
 
 
3e1cf28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b4a8f62
 
 
 
 
 
 
 
 
 
 
3e1cf28
 
 
 
 
 
 
 
9672344
 
 
 
 
 
 
 
 
 
 
 
 
 
b735d78
c48a16c
2e9a2d0
 
 
 
 
 
f85f6f1
2e9a2d0
 
 
 
8baf562
 
 
 
 
 
 
 
 
 
 
 
 
b4a8f62
 
 
b16e88e
0cc15f2
 
b4a8f62
0cc15f2
2c422c6
 
b4a8f62
3e1cf28
 
 
 
 
 
b4a8f62
3e1cf28
 
 
 
2e9a2d0
3e1cf28
 
 
 
2e9a2d0
 
 
 
 
 
 
 
3e1cf28
 
 
 
 
 
 
 
 
 
 
 
b4a8f62
 
 
3e1cf28
b4a8f62
3e1cf28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b4a8f62
3e1cf28
 
 
b4a8f62
 
 
 
 
 
 
 
3e1cf28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# 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"
    )
  )
)