Nothing
# ============================ #
# The dashboard, user surface #
# ============================ #
#' @noRd
volumr_css <- function() {
htmltools::tags$style(htmltools::HTML("
.theory-content { font-size: 14px; line-height: 1.55; }
.theory-content h4 { margin-top: 18px; font-weight: 600; }
.plot-container { background: #fff; padding: 6px; border-radius: 4px; }
.frame-container { height: 640px; }
.frame-container-tall { height: 780px; }
.frame-container-tall .html-widget { height: 100% !important; }
.frame-container .html-widget { height: 100% !important; }
.small-note { color: #777; font-size: 12px; }
.box-title { font-weight: 600; }
pre.console { background: #1b1f23; color: #e6edf3; font-size: 12px;
padding: 10px; border-radius: 4px; max-height: 320px;
overflow: auto; }
"))
}
#' @noRd
tab_home <- function() {
shinydashboard::tabItem(
"home",
shiny::fluidRow(
shinydashboard::infoBoxOutput("box_grid", width = 3),
shinydashboard::infoBoxOutput("box_levels", width = 3),
shinydashboard::infoBoxOutput("box_coverage", width = 3),
shinydashboard::infoBoxOutput("box_payload", width = 3)),
shiny::fluidRow(
shinydashboard::box(
title = "The workflow", width = 8, status = "primary",
solidHeader = TRUE,
shiny::div(class = "theory-content", shiny::HTML(
"<p>A gridded three-dimensional field becomes a volume a browser
can render in four steps, and every tab of this application is
one of them.</p>
<p><b>Data</b> reads the field, from the case study or from a
file of your own, and reports the grid and the coverage.
<b>Encoding</b> puts the depth axis on a uniform grid and
carries the values into 8 bits, measuring what that costs.
<b>Payload</b> writes one image per level with a manifest, and
offers the single file that carries all of it.
<b>Volume</b> renders it, with every control the page has.</p>
<p>The three tabs after those state the mathematics the render
follows, what the view cannot tell you, and where the case
study comes from.</p>"))),
shinydashboard::box(
title = "The field in hand", width = 4, status = "info",
solidHeader = TRUE,
shiny::verbatimTextOutput("home_field"),
shiny::uiOutput("home_source"))),
shiny::fluidRow(
shinydashboard::box(
title = "Coverage against depth", width = 6, status = "info",
solidHeader = TRUE,
shiny::div(class = "plot-container",
shiny::plotOutput("home_coverage", height = 300))),
shinydashboard::box(
title = "The quantity against depth", width = 6, status = "info",
solidHeader = TRUE,
shiny::div(class = "plot-container",
shiny::plotOutput("home_profile", height = 300)))))
}
#' @noRd
tab_data <- function() {
shinydashboard::tabItem(
"data",
shiny::fluidRow(
shinydashboard::box(
title = "Choose a field", width = 4, status = "primary",
solidHeader = TRUE,
shiny::radioButtons(
"source_kind", NULL,
c("The case study that ships with the package" = "packaged",
"A file of my own" = "upload"), selected = "packaged"),
shiny::conditionalPanel(
"input.source_kind == 'upload'",
shiny::fileInput("upload", "Field file",
accept = c(".rds", ".RDS", ".nc", ".nc4",
".csv", ".rda", ".RData", ".npy")),
shiny::helpText(shiny::HTML(
"An <code>.rds</code> holding a <code>vol_field</code>, or a
list with <code>values</code>, <code>lon</code>,
<code>lat</code> and <code>depth</code>; a NetCDF file; a
<code>.csv</code> of one row per cell, with three
coordinate columns and one value column; or an
<code>.rda</code> carrying one such object.")),
shiny::uiOutput("nc_controls")),
shiny::hr(),
shiny::sliderInput("step", "Horizontal decimation", 1, 8, 1, 1),
shiny::helpText("1 keeps the native grid. Raise it to make a large field responsive."),
shiny::actionButton("load", "Load the field", class = "btn-primary",
width = "100%")),
shinydashboard::box(
title = "Field summary", width = 8, status = "info",
solidHeader = TRUE,
shiny::verbatimTextOutput("data_summary"),
shiny::uiOutput("data_message"))),
shiny::fluidRow(
shinydashboard::box(
title = "One level", width = 7, status = "info", solidHeader = TRUE,
shiny::fluidRow(
shiny::column(6, shiny::uiOutput("level_slider")),
shiny::column(6, shiny::selectInput("map_cmap", "Colour table",
vol_colormaps()))),
shiny::div(class = "plot-container",
shiny::plotOutput("data_level", height = 380))),
shinydashboard::box(
title = "Level by level", width = 5, status = "info",
solidHeader = TRUE,
shiny::tableOutput("data_levels"))))
}
#' @noRd
tab_encoding <- function() {
shinydashboard::tabItem(
"encoding",
shiny::fluidRow(
shinydashboard::box(
title = "Resample and quantise", width = 4, status = "primary",
solidHeader = TRUE,
shiny::checkboxInput("resample", "Put the depth axis on a uniform grid",
TRUE),
shiny::uiOutput("dz_control"),
shiny::radioButtons("transfer", "Transfer into 8 bits",
c("Square root" = "sqrt", "Linear" = "linear")),
shiny::helpText(shiny::HTML(
"The square root spends the 254 codes where a positive skewed
field puts its cells. The linear ramp is the right choice for a
field that is not skewed, and the only choice for one that
takes negative values.")),
shiny::actionButton("encode", "Encode", class = "btn-primary",
width = "100%")),
shinydashboard::box(
title = "Transfer error", width = 8, status = "info",
solidHeader = TRUE,
shiny::verbatimTextOutput("encode_summary"),
shiny::uiOutput("encode_message"))),
shiny::fluidRow(
shinydashboard::box(
title = "Error against the value", width = 6, status = "info",
solidHeader = TRUE,
shiny::div(class = "plot-container",
shiny::plotOutput("encode_value", height = 330))),
shinydashboard::box(
title = "Error against depth", width = 6, status = "info",
solidHeader = TRUE,
shiny::div(class = "plot-container",
shiny::plotOutput("encode_depth", height = 330)))))
}
#' @noRd
tab_payload <- function() {
shinydashboard::tabItem(
"payload",
shiny::fluidRow(
shinydashboard::box(
title = "Write the payload", width = 4, status = "primary",
solidHeader = TRUE,
shiny::uiOutput("limits_control"),
shiny::selectInput("cmap", "Colour table the viewer opens with",
vol_colormaps()),
shiny::sliderInput("gamma", "Gamma", 0.3, 3, 1, 0.05),
shiny::textInput("title", "Title", ""),
shiny::textInput("subtitle", "Subtitle", ""),
shiny::actionButton("build", "Build", class = "btn-primary",
width = "100%"),
shiny::hr(),
shiny::downloadButton("download_page", "Download the single file",
style = "width:100%"),
shiny::p(class = "small-note",
"One HTML file carrying the whole volume. It opens by double-click, with no server.")),
shinydashboard::box(
title = "Payload summary", width = 8, status = "info",
solidHeader = TRUE,
shiny::verbatimTextOutput("payload_summary"),
shiny::uiOutput("payload_message"))),
shiny::fluidRow(
shinydashboard::box(
title = "Payload size by file", width = 6, status = "info",
solidHeader = TRUE,
shiny::div(class = "plot-container",
shiny::plotOutput("payload_size", height = 330))),
shinydashboard::box(
title = "A level as the browser reads it", width = 6,
status = "info", solidHeader = TRUE,
shiny::uiOutput("decoded_slider"),
shiny::div(class = "plot-container",
shiny::plotOutput("payload_level", height = 300)))))
}
#' @noRd
tab_volume <- function() {
shinydashboard::tabItem(
"volume",
shiny::fluidRow(
shinydashboard::box(
title = "The volume", width = 12, status = "primary",
solidHeader = TRUE,
shiny::div(class = "frame-container-tall",
vol_widget_output("volume", height = "100%")),
shiny::fluidRow(
shiny::column(7, shiny::p(class = "small-note",
shiny::textOutput("view_source"))),
shiny::column(5, shiny::p(class = "small-note",
shiny::textOutput("camera_line")))))),
shiny::fluidRow(
shinydashboard::box(
title = "Panel controls", width = 12, status = "info",
solidHeader = TRUE, collapsible = TRUE, collapsed = TRUE,
shiny::div(class = "theory-content", shiny::HTML(
"<p>The controls to the right of the volume belong to the page
itself, so what you set here is what the downloaded file
carries, and there is no second copy of them to drift.</p>
<p><b>Colour</b> chooses one of five perceptually uniform
tables, sets the ends of the scale in the units of the field,
bends it with a gamma, and swaps the whole page to a white
background for a figure that goes into print.</p>
<p><b>Density</b> quotes the opacity a ray accumulates across
the depth range the box spans, so it does not drift when the
box is stretched or turned; the second slider makes weak water
transparent.</p>
<p><b>Depth slab</b> slides a window of fixed thickness through
the depth range, holding its opacity so that a thin slab reads as
strongly as the whole column, and sweeps it downward on a
button. A feature that survives a thin window is local to that
depth; one that fades was an accumulation along the ray.</p>
<p><b>Geometry</b> stretches the vertical axis, frames the box
on a depth range, so that a shallow layer of a deep field fills
the box, cuts the volume in longitude and latitude, and switches to a parallel
projection, which is what makes the map view a plan with one
scale everywhere in it.</p>
<p><b>Quality and viewpoints</b> set the sampling of the ray,
turn the camera, and restore either the oblique framing of the
printed figure or the map view from above.</p>
<p>Hover over the volume to read the position and the value
under the cursor. The figure quoted is taken from the place
along the line of sight where the accumulated opacity first
passes a half, which is the cell the eye is looking at rather
than the cell nearest the pointer.</p>
<p>The box is drawn in the proportions of the data. Longitude
is scaled by the cosine of the latitude of the domain, so the
shapes are the ones an atlas draws; the depth axis cannot be
to scale against a basin thousands of kilometres wide, so the
vertical exaggeration slider reports the factor it implies.</p>")))))
}
#' @noRd
tab_theory <- function() {
shinydashboard::tabItem(
"theory",
shiny::fluidRow(shinydashboard::box(
title = "Rendering equations", width = 12, status = "primary",
solidHeader = TRUE,
shiny::div(class = "theory-content", shiny::withMathJax(shiny::HTML(
"<h4>The volume integral</h4>
<p>Every pixel casts one ray through the box. Along it the renderer
accumulates colour and opacity front to back, which is the discrete
form of the emission and absorption integral,
$$C = \\int_{t_0}^{t_1} c(t)\\,\\sigma(t)\\,
e^{-\\int_{t_0}^{t}\\sigma(s)\\,ds}\\,dt,$$
with \\(c\\) the colour the transfer function gives the sample and
\\(\\sigma\\) the extinction per unit length. Over a step of length
\\(\\Delta t\\) the sample contributes an opacity
\\(\\alpha = 1 - e^{-\\sigma \\Delta t}\\), and the compositing rule
is \\(C \\leftarrow C + (1-A)\\,\\alpha\\,c\\) and
\\(A \\leftarrow A + (1-A)\\,\\alpha\\).</p>
<h4>Why the density does not drift</h4>
<p>The control quotes \\(\\tau\\), the optical depth accumulated
across the depth range the box spans, and the renderer converts it to
\\(\\sigma = \\tau / H\\) with \\(H\\) the height of the box in world
units. Because \\(\\sigma\\) is an extinction per unit length and the
path through the box is \\(H\\), the accumulated opacity
\\(1 - e^{-\\tau}\\) does not change when the box is stretched or the
camera is turned, which a fixed opacity per surface cannot promise.</p>
<h4>Holding the opacity of a slab</h4>
<p>A window of thickness \\(T\\) out of a span \\(Z\\) accumulates
\\(\\tau T / Z\\), so a thin slab is faint. With the opacity held the
renderer uses \\(\\sigma = \\tau / T\\) instead, and the slab reaches
the same \\(1 - e^{-\\tau}\\) whatever its thickness. Measured on the
case study at \\(\\tau = 3.5\\), a 12.5 m slab reads 0.9702 against the
0.9698 the formula predicts, and 0.1612 against 0.1605 with the hold
cleared.</p>
<h4>The transfer into 8 bits</h4>
<p>With \\(N = 254\\) codes available and 0 reserved for a missing
cell, the square-root transfer writes
$$c = 1 + \\mathrm{round}\\!\\left((N-1)\\,
\\frac{\\sqrt{v}-\\sqrt{v_{lo}}}{\\sqrt{v_{hi}}-\\sqrt{v_{lo}}}\\right),$$
and the renderer inverts it by squaring. The Encoding tab measures
what that costs against the values it started from.</p>
<h4>The depth window</h4>
<p>The window is a slab in world \\(z\\). The ray is clamped to it
before it marches, so the step follows the thickness of the window
and not the height of the box, and a thin slab is sampled as finely
as the whole column.</p>")))))
)
}
#' @noRd
tab_limits <- function() {
shinydashboard::tabItem(
"limits",
shiny::fluidRow(shinydashboard::box(
title = "Limits of the view", width = 12,
status = "warning", solidHeader = TRUE,
shiny::div(class = "theory-content", shiny::HTML(
"<p>A volume rendering is an integral along a ray, so a bright region
may be one intense cell or a long column of moderate ones. Use the
depth slab to separate the two: a feature that survives a thin
window is local, and one that fades is an accumulation along the
ray.</p>
<p>The colour scale saturates at both ends and neither the volume nor
the colour bar says how far past a limit a cell sits. Move the limits
to read the tail.</p>
<p>The slab composites from the front, so its colour is not the mean
over the window. At a high opacity the front face dominates and the
map reports the shallow end of the window.</p>
<p>The vertical axis is exaggerated: the box takes its horizontal
proportions from the data, but a depth of a few hundred metres
against a basin thousands of kilometres wide has to be stretched to
be seen, and the panel reports the factor. A distance read across
the volume is therefore not comparable with a distance read down
it, except in the map view, where the exaggeration has no
effect.</p>
<p>Values travel in 8 bits. The Encoding tab reports the error that
costs, and it is small against the width of a plotted colour band,
but it is not zero.</p>
<p>Cells that carry no value are not drawn, so the shape of the
volume is the shape of the domain and not a contour of the
quantity.</p>"))))
)
}
#' @noRd
tab_about <- function() {
shinydashboard::tabItem(
"about",
shiny::fluidRow(
shinydashboard::box(
title = "The case study", width = 7, status = "primary",
solidHeader = TRUE,
shiny::div(class = "theory-content", shiny::uiOutput("about_data"))),
shinydashboard::box(
title = "The package", width = 5, status = "info",
solidHeader = TRUE,
shiny::div(class = "theory-content", shiny::HTML(
"<p><b>volumr</b>, by Pablo Almaraz
(<a href='https://orcid.org/0000-0003-1416-2695'>ORCID
0000-0003-1416-2695</a>), Manuel Fernandez-Barba
(<a href='https://orcid.org/0000-0001-8953-2481'>ORCID
0000-0001-8953-2481</a>) and
<a href='https://datalab-icman.github.io/'>DataLab ICMAN</a>,
released under the GNU General Public License version 3.</p>
<p>Cite the package as:</p>
<p><code>Almaraz, P., Fernandez-Barba, M., & DataLab ICMAN
(2026). volumr: interactive volume rendering of gridded
three-dimensional fields. R package version 0.1.0.</code></p>")),
shiny::verbatimTextOutput("about_session"))))
}
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.