inst/app/alignment_ui.R

fluidPage(theme = "zoo.css",
  tags$style(HTML("\
    #alignment-comparison { display:grid; gap:12px; grid-template-rows:minmax(360px, 44vh) minmax(360px, 44vh); }
    #alignment-comparison.alignment-unaligned { grid-template-rows:minmax(500px, 72vh) minmax(120px, 18vh); }
    #alignment-comparison.alignment-aligned { grid-template-rows:minmax(120px, 18vh) minmax(500px, 72vh); }
    .alignment-panel { border:1px solid #ddd; border-radius:4px; padding:8px 12px; min-height:120px; overflow:hidden; display:flex; flex-direction:column; }
    .alignment-panel > h4 { flex:0 0 auto; margin:0 0 4px 0; }
    .alignment-panel > .shiny-panel-conditional { flex:1 1 auto; min-height:0; }
    .spectra-plot-wrap { position:relative; height:100%; }
    .alignment-region-preview { position:absolute; display:none; z-index:9; pointer-events:none; background:rgba(255,127,14,0.18); border-left:2px solid #ff7f0e; border-right:2px solid #ff7f0e; }
    .spectra-hover-label { position:absolute; z-index:10; pointer-events:none; text-align:left; background:rgba(255,255,255,0.92); border:1px solid #999; border-radius:3px; padding:3px 6px; font-size:12px; white-space:nowrap; }
    .alignment-toolbar .well { padding:6px 10px; margin-bottom:6px; }
    .alignment-toolbar .form-group { margin-bottom:0; }
    .alignment-toolbar h5 { margin:0 0 3px 0; font-size:11px; font-weight:bold; text-transform:uppercase; letter-spacing:0.04em; color:#666; }
    .alignment-toolbar .shiny-input-container-inline .control-label { display:block; margin:0; }
    .alignment-toolbar .radio-inline { margin:0; padding:0; }
    .alignment-toolbar .radio-inline + .radio-inline { margin-left:0; }
    .alignment-toolbar .radio-inline > input { position:absolute; opacity:0; width:0; height:0; }
    .alignment-toolbar .radio-inline > span { display:inline-block; padding:5px 11px; font-size:12px; font-weight:bold; color:#000; border:1px solid #1E90FF; border-left-width:0; cursor:pointer; }
    .alignment-toolbar .radio-inline:first-child > span { border-left-width:1px; border-radius:4px 0 0 4px; }
    .alignment-toolbar .radio-inline:last-child > span { border-radius:0 4px 4px 0; }
    .alignment-toolbar .radio-inline > span:hover { background:rgba(30,144,255,0.15); }
    .alignment-toolbar .radio-inline > input:checked + span { background:#1E90FF; color:#FFFFFF; }
    .alignment-toolbar .btn { padding:2px 6px; }
    .alignment-help-col { padding-top:20px; }
    .alignment-toolbar .btn-help { padding:4px 11px; font-size:15px; line-height:1.2; }
    .popover { max-width:460px; }
    .popover-content p { margin:0 0 7px 0; }
    .popover-content p:last-child { margin-bottom:0; }
    #icoshift_settings .panel-title a { display:block; font-weight:bold; color:#000; text-decoration:none; }
    #icoshift_settings .panel-title a:after { content:'\\25B8'; float:right; color:#1E90FF; }
    #icoshift_settings .panel-title a[aria-expanded=true]:after { content:'\\25BE'; }
    #icoshift_status { white-space:pre-wrap; word-break:break-word; }
    .alignment-legend { display:flex; flex-wrap:wrap; align-items:center; gap:6px 18px; font-size:12px; color:#555; margin:0 0 8px 0; padding:0 2px; text-align:left; }
    .alignment-legend .swatch { display:inline-block; width:24px; height:0; vertical-align:middle; margin-right:6px; }
    .alignment-legend .swatch-proposal { border-top:3px solid #1f77b4; }
    .alignment-legend .swatch-applied { border-top:3px dashed #2ca02c; }
    .alignment-legend .status { margin-left:auto; font-style:italic; color:#777; }
    .alignment-empty { font-size:12px; color:#888; font-style:italic; }
    @media (max-width: 768px) {
      #alignment-comparison, #alignment-comparison.alignment-unaligned, #alignment-comparison.alignment-aligned {
        grid-template-rows:320px 320px;
      }
    }
  ")),
  tags$script(HTML("\
    $(document).on('change', 'input[name=alignment_layout]', function() {
      var comparison = $('#alignment-comparison');
      comparison.removeClass('alignment-unaligned alignment-aligned');
      if (this.value === 'unaligned') comparison.addClass('alignment-unaligned');
      if (this.value === 'aligned') comparison.addClass('alignment-aligned');
      window.setTimeout(function() { $(window).trigger('resize'); }, 0);
    });
    // The slider inside the collapsed panel is laid out while hidden; a resize
    // after the panel opens gives it its real width.
    $(document).on('shown.bs.collapse', function() {
      window.setTimeout(function() { $(window).trigger('resize'); }, 0);
    });
  ")),
  tags$script(src = "alignment_regions.js"),
  tags$h3("Spectrum alignment"),
  fluidRow(
    column(3, align = "left",
      sidebarPanel(width = 12,
        radioButtons(
          "icoshift_mode", "Workflow",
          choices = c("Automatic (detect and align)" = "automatic",
                      "Manual / assisted" = "manual"),
          selected = "manual"
        ),
        bsTooltip("icoshift_mode",
                  "Automatic detects the regions and aligns in one action; manual lets you review them first.",
                  "right", options = list(container = "body")),
        bsCollapse(
          id = "icoshift_settings",
          bsCollapsePanel(
            "Detection settings",
            sliderInput(
              "icoshift_detection_sensitivity",
              "Detection sensitivity",
              min = 1, max = 9, value = 5, step = 1
            ),
            bsTooltip("icoshift_detection_sensitivity",
                      "Higher values detect more and narrower regions.",
                      "right", options = list(container = "body")),
            textInput(
              "icoshift_frequency_mhz",
              "Frequency (MHz, optional)",
              value = ""
            ),
            bsTooltip("icoshift_frequency_mhz",
                      "Spectrometer frequency, used to group J-coupled peaks.",
                      "right", options = list(container = "body")),
            checkboxInput(
              "icoshift_use_j",
              "Use cautious J grouping",
              value = TRUE
            ),
            bsTooltip("icoshift_use_j",
                      "Keeps coupled peaks of the same multiplet inside one region.",
                      "right", options = list(container = "body"))
          )
        ),
        selectInput(
          "icoshift_reference",
          "Alignment reference",
          choices = c("Average spectrum" = "average"),
          selected = "average"
        ),
        bsTooltip("icoshift_reference",
                  "Spectrum used as the alignment target.",
                  "right", options = list(container = "body")),
        conditionalPanel(
          condition = "input.icoshift_mode == 'automatic'",
          actionButton("icoshift_auto_align", "Detect and align",
                       class = "btn-primary"),
          bsTooltip("icoshift_auto_align",
                    "Detect regions and apply them atomically in one action.",
                    "right", options = list(container = "body"))
        ),
        conditionalPanel(
          condition = "input.icoshift_mode == 'manual'",
          textAreaInput(
            "icoshift_intervals",
            "PPM intervals",
            value = "-0.1, 0.1", rows = 5, width = "100%"
          ),
          bsTooltip("icoshift_intervals",
                    "Current values; original values in parentheses.",
                    "right", options = list(container = "body")),
          actionButton("icoshift_detect", "Suggest regions"),
          bsTooltip("icoshift_detect",
                    "Detect a suggestion and review it before aligning.",
                    "right", options = list(container = "body")),
          tags$span(style = "display:inline-block; width:5px;"),
          actionButton("icoshift_align", "Confirm and align",
                       class = "btn-primary"),
          bsTooltip("icoshift_align",
                    "Align using the regions listed above.",
                    "right", options = list(container = "body"))
        ),
        tags$hr(),
        tags$b("Alignment status"),
        verbatimTextOutput("icoshift_status")
      )
    ),
    column(9, align = "center",
      # One toolbar instead of three stacked control groups plus their
      # instruction paragraphs: each control carries its own tooltip and the
      # "?" button holds everything that needs more than one sentence.
      tags$div(class = "alignment-toolbar",
        sidebarPanel(width = 12,
          fluidRow(
            column(4, align = "left",
              radioButtons(
                "alignment_layout", h5("Comparison layout"),
                choices = c("Balanced" = "balanced",
                            "Unaligned" = "unaligned",
                            "Aligned" = "aligned"),
                selected = "balanced", inline = TRUE
              ),
              bsTooltip("alignment_layout",
                        "Give more height to one of the two panels.",
                        "bottom", options = list(container = "body"))
            ),
            column(4, align = "center",
              tags$h5("View"),
              tags$button(id = "alignment_pan_left",
                          class = "btn action-button btn_lmax",
                          title = "Pan to higher ppm",
                          `aria-label` = "Pan to higher ppm",
                          tags$img(src = "s_left.png",
                                   height = "35px", width = "40px")),
              bsTooltip("alignment_pan_left", "Pan to higher ppm",
                        "bottom", options = list(container = "body")),
              tags$button(id = "alignment_zoom_out",
                          class = "btn action-button btn_r",
                          title = "Zoom out",
                          `aria-label` = "Zoom out",
                          tags$img(src = "cont.png",
                                   height = "35px", width = "40px")),
              bsTooltip("alignment_zoom_out", "Zoom out",
                        "bottom", options = list(container = "body")),
              tags$button(id = "alignment_pan_right",
                          class = "btn action-button btn_l",
                          title = "Pan to lower ppm",
                          `aria-label` = "Pan to lower ppm",
                          tags$img(src = "s_right.png",
                                   height = "35px", width = "40px")),
              bsTooltip("alignment_pan_right", "Pan to lower ppm",
                        "bottom", options = list(container = "body")),
              tags$button(id = "alignment_reset_view",
                          class = "btn action-button btn_r",
                          title = "Reset synchronized view",
                          `aria-label` = "Reset synchronized view",
                          tags$img(src = "rsh.png",
                                   height = "35px", width = "40px")),
              bsTooltip("alignment_reset_view", "Reset synchronized view",
                        "bottom", options = list(container = "body"))
            ),
            column(3, align = "right",
              radioButtons(
                "alignment_mouse_mode", h5("Mouse drag"),
                choices = c("Zoom" = "zoom", "Edit regions" = "regions"),
                selected = "zoom", inline = TRUE
              ),
              bsTooltip("alignment_mouse_mode",
                        "Zoom: drag over either plot to zoom both. Edit regions: drag to add, move or resize a region.",
                        "bottom", options = list(container = "body"))
            ),
            column(1, align = "right", class = "alignment-help-col",
              tags$button(id = "alignment_help", type = "button",
                          class = "btn btn-help",
                          title = "How this page works",
                          `aria-label` = "How this page works", "?"),
              bsPopover(
                "alignment_help", "Alignment page",
                paste0(
                  "<p>Optional next step after import: compare and align the ",
                  "spectra before selecting signals or running STOCSY.</p>",
                  "<p><b>Mouse drag, Zoom:</b> drag over either plot to zoom ",
                  "both; double-click to reset.</p>",
                  "<p><b>Mouse drag, Edit regions:</b> drag a region limit to ",
                  "resize it, drag inside a region to move it, drag elsewhere ",
                  "to add one; double-click a region to remove it. The blue ",
                  "proposal and the interval text update without aligning.</p>",
                  "<p><b>Colours:</b> blue is the current proposal; green ",
                  "dotted are unchanged applied regions. The green outline ",
                  "disappears when its region is edited. New regions appear ",
                  "only in blue; removed regions remain only in green until ",
                  "the next alignment.</p>",
                  "<p>Click a curve to highlight it in both panels; click it ",
                  "again or click empty space to clear.</p>"
                ),
                placement = "left", trigger = "click",
                options = list(container = "body", html = TRUE)
              )
            )
          )
        )
      ),
      tags$div(class = "alignment-legend",
        tags$span(tags$i(class = "swatch swatch-proposal"), "current proposal"),
        tags$span(tags$i(class = "swatch swatch-applied"), "applied regions"),
        tags$span(class = "status",
                  textOutput("alignment_highlight_text", inline = TRUE))),
      tags$div(id = "alignment-comparison",
        class = "alignment-balanced",
        tags$section(class = "alignment-panel", id = "alignment-unaligned-panel",
          tags$h4("Unaligned spectra"),
          conditionalPanel(
            condition = "!output.alignment_original_available",
            tags$p(class = "alignment-empty",
                   "Import spectra to display the unaligned data.")),
          conditionalPanel(
            condition = "output.alignment_original_available",
            tags$div(class = "spectra-plot-wrap",
              plotOutput("alignment_unaligned_plot", height = "100%",
                click = "alignment_unaligned_click",
                dblclick = "alignment_unaligned_dblclick",
                hover = hoverOpts("alignment_unaligned_hover", delay = 120,
                                  delayType = "debounce", nullOutside = TRUE),
                brush = brushOpts("alignment_unaligned_brush", direction = "xy",
                                  fill = "#ccc", resetOnNew = TRUE)),
              uiOutput("alignment_unaligned_hover_label", inline = TRUE)))
        ),
        tags$section(class = "alignment-panel", id = "alignment-aligned-panel",
          tags$h4("Aligned spectra"),
          conditionalPanel(
            condition = "!output.alignment_result_available",
            tags$p(class = "alignment-empty", "No aligned result yet.")),
          conditionalPanel(
            condition = "output.alignment_result_available",
            tags$div(class = "spectra-plot-wrap",
              plotOutput("alignment_aligned_plot", height = "100%",
                click = "alignment_aligned_click",
                dblclick = "alignment_aligned_dblclick",
                hover = hoverOpts("alignment_aligned_hover", delay = 120,
                                  delayType = "debounce", nullOutside = TRUE),
                brush = brushOpts("alignment_aligned_brush", direction = "xy",
                                  fill = "#ccc", resetOnNew = TRUE)),
              uiOutput("alignment_aligned_hover_label", inline = TRUE)))
        )
      ),
      tags$hr(),
      conditionalPanel(
        condition = "!output.icoshift_detection_available",
        tags$p(class = "alignment-empty",
               "No detected regions yet. Use Detect and align, or Suggest regions.")
      ),
      # The three audit tables become tabs; the editable plot stays on the
      # first one. Both hidden tables keep suspendWhenHidden = FALSE in
      # Pretreatment_server.R so they stay rendered behind their tabs.
      conditionalPanel(
        condition = "output.icoshift_detection_available",
        tabsetPanel(
          id = "icoshift_audit",
          tabPanel("Regions",
            plotOutput("icoshift_detection_plot", height = "420px",
                       brush = brushOpts(id = "icoshift_region_brush",
                                         direction = "x", resetOnNew = TRUE),
                       dblclick = "icoshift_region_remove"),
            bsTooltip("icoshift_detection_plot",
                      "Blue limits are the editable regions: drag across the plot to add one, double-click inside a region to remove it.",
                      "top", options = list(container = "body")),
            tableOutput("icoshift_regions_table")),
          tabPanel("Peak evidence",
            tableOutput("icoshift_detection_table")),
          tabPanel("Applied",
            tableOutput("icoshift_applied_regions_table"))
        )
      )
    )
  )
)

Try the iSTATS package in your browser

Any scripts or data that you put into this service are public.

iSTATS documentation built on Nov. 6, 2026, 1:07 a.m.