Spectran - Spectral analysis of light - Shiny Contest Submission

Spectran - Spectral analysis of light

Authors: Johannes Zauner

Abstract: Spectran is an analysis tool for visualizing and calculating core metrics for light spectra (visible radiation), with applications in education, research, and lighting design. It allows the import of CSV measurement data, has many example spectra, and even allows you to create your spectrum - or adjust existing ones. It is used to teach students about light and its spectral composition, to make presentation and publication-ready, appealing graphs and tables, and to explore one's measurements in a fun and accessible way.
Spectran was pitched to the German Society for lighting technology and lighting design and was accepted as an official tool, with adjustments to the society's design (https://www.litg.de). The application is available in English and German, and is available on CRAN as well.

Full Description:

What is Spectran about?

Spectran, or "Spectral Analysis" deals with measurements of light that reveal their spectral composition, which we humans interpret as colours of light. Such measurements are taken with spectroradiometers and are used in many fields, such as lighting research, architecture and lighting design, or in the arts. Measurement devices come bundled with proprietary software, which is often clunky and unintuitive to use, output leaves much to be desired visually, and the software is not openly available, so that others can't easily reproduce the results. Spectran solves all of that by providing a free, open-source, and easy-to-use tool for the analysis of light spectra.

Spectran is self-explanatory in the sense that the description of what it can do and how it does it is contained in the tool itself. It is used to teach students about light and its spectral composition, for researchers and lighting designers to make presentation and publication-ready, appealing graphs and tables, and to explore one's measurements in a fun and accessible way. It is available in English and German, and is available on CRAN as well.

Why did I create Spectran?

My background is in architecture first and human biology second, and one intersection of those fields are the health related effects of light on humans, e.g. on the sleep-wake cycle, mood, or cognitive performance. With the emergence of this topic in science, design, and the public discourse, new metrics to quantify light for visual, as well as those non-visual effects, became necessary. Most people I talk to outside my research bubble, and especially my students need to grasp the concept of light spectra and their effects quickly so that they can apply it in their work.

When I just started out with R and Shiny (architects are not known for their programming skills...), I thought that a tool that could easily import and visualize light spectra, calculate core metrics, and provide an accessible and engaging way to explore the topic would be a fun challenge for myself.

What was the development process like?

During a two week holiday break, after my daughter went to bed each day, I would sit down and add one feature after another, until I had a working, but often crashing prototype. Showing this to colleagues and trying it with students, I got so much positive feedback about the concepts and visuals, that I decided this was worth developing further.

I pitched the project to the German Society for lighting technology and lighting design (https://www.litg.de), and they provided me with a small grant to rework the tool to fit their design guidelines. Meanwhile, I had read through the different books by Hadley Wickham, like Mastering Shiny and Advanced R, and I incorporated many of the concepts I had learned there into the final version of Spectran, like modules and meta-programming.

What I am particularly proud about with Spectran

Modular, extendable design

Spectran is built around a pipeline of reactive data cores, where modules for import, analysis, and export read from and feed into. This makes the development of further modules easy, as they can be added to the pipeline without changing the core of the app. This was tricky to get right, as it is easy to feed data to a module and then get data back to be tied to a variable, but more difficult to exchange data between modules in a centralized fashion.

Multilanguage support & easy addition of example spectra

Spectran utilizes external data from excel files that can be adjusted and extended (and are converted to .rda files before building the app-package). One file contains the languages. Currently, Spectran supports English and German, but other languages could be easily added as new columns. The way this works is that at the start of the app, the language argument is set and stored in an environment. Whenever text is displayed, it is not written out in the app, but a row number from the language dataframe is referenced, where the column is the language specified in the environment. This way, the app can be easily translated into other languages by adding more columns.

Similarly, the example spectra and their metadata are read in from an excel file. Through modules and purrr-style programming, the example spectra section is built automatically and can be extended for as many examples as required.

Responsive app with layered image generation

Spectran creates many images from the spectral data, which takes computation time. As the app uses many pages, this is no problem as such, as only the current pages' images are updated. However, this leaves the user with waiting times whenever a new analysis tab is opened. To simply overwrite the behavior of the app to update all images at once would lead to a lot of waiting time whenever the user imports a spectrum. The final solution is a trick utilizing user behavior. Only the image of the first analysis page is generated in the background when data gets imported. When the app switches to that page, it is instantly present. At that moment, the other images are generated in the background. This way, while the user looks at the first analysis-results, the other tabs get populated with images, so that when the user switches to them, they are already there with no waiting time.

Multiple entrypoints for spectra (import, examples, sandbox, adjustment) without crashing the app

Not everyone has their own measurement data, so Spectran provides different entrypoints. I already mentioned the example spectra, but there is also a sandbox mode, where people can create their own spectrum by clicking into the figure. Moreover, if the user already has a spectrum, they can adjust it in this graph by returning to the import section, and then clicking on the adjust button. It will be transferred to the sandbox, and data points can be removed by draging and clicking, or added by clicking. This way, the user can see how certain aspects and features of a spectrum contribute to various metrics. To get all of this right without making the app prone to crashes or bugs was a challenge, but it works smoothly now.

My first package on CRAN

This speaks for itself :).

Dabbling into the world of HTML and CSS to style the app to the CI

Architects are not graphic designers, let me tell you that, but I think the end result looks pretty good. The overall design resembles the design of the German Society for lighting technology and lighting design (https://www.litg.de), and I think it looks professional and appealing. While far from an expert, this meant stepping into the world of raw HTML and CSS to set colors and the behavior of certain elements, which I found very rewarding, if puzzling at times.


Shiny app: Spectran
Repo: GitHub - LiTGde/Spectran: Visual and Non-Visual Spectral Analysis of Light

Thumbnail:
image

Full image: