Press "Enter" to skip to content

Category: Visualization

Modularizing an Existing Shiny App

Peter Baranovskiy breaks it down:

There are multiple tutorials available online on writing modular Shiny apps. So why one more? Well, when I just started with building modular apps myself, these didn’t do much for me. So I really only learned how to write modules when I had an opportunity to team up with an experienced R Shiny developer. The reason I guess is that Shiny modules is an advanced topic, and you typically get to writing modules only when you finally need to scale your apps – and keep opportunities for further scaling open. This typically means when your app goes into production. By then you probably have already developed multiple apps, and switching over to a way of thinking required to write modules may be challenging. If you don’t know what modules are, I recommend starting here and then coming back to this post. Otherwise, read on.

So, I decided to try a different approach and instead of building a simple modular app from scratch, to go in the opposite direction by breaking down a complex real-life app into modules. Here’s the app’s original non-modular code. Note a single app.R file that contains the entire app. static_assets.R includes some object definitions which I moved to a separate file for convenience. calgary_crime_data_prep.R is not part of the app; it is a data retrieval and cleaning script executed once a month with cron. Running the script each time the app launches would have made it extremely slow and would use way too much bandwidth, as the script downloads and processes 150+ Mb of data on each run.

Read on for the reasoning behind using modules, as well as Peter’s notes on the process.

Comments closed

Power BI Treemap Visual Desired Enhancements

Meagan Longoria has an airing of grievances:

I recently created a treemap in Power BI for a Workout Wednesday challenge. Originally, I had set out to make a different treemap, but I ran into some limitations with the visual. I ended up with the treemap below, which isn’t bad, but it made me realize that the treemap is in need of some improvements to make it really useful. So I decided to share my thoughts here.

Read on for Meagan’s thoughts on the existing treemap visual. I agree with all of Meagan’s points and would love to see this visual be updated.

Comments closed

TreeMaps vs Pie Charts

Rita Fainshtein talks treemaps:

The main challenge arises from the difficulty in comparing the areas of the segments within the chart.

Consequently, pie charts and similar graphs become challenging to interpret.

Colors for categories don’t make it easy either since the brain tries to figure out how the color relates to the category, which in the example here just happens to be a random choice.

Let’s see if the Treemap helps and make it easier.

Rita notes that treemaps work well in a specific niche: hierarchical, categorical data. But within their niche, they work really well, which is more than you can say about pie charts…

Comments closed

Customizing a Shiny App Theme

Peter Baranovskiy doesn’t want bog standard but is okay with mostly standard:

There are multiple ways to style or theme a Shiny app. A high-level overview is available in the Mastering Shiny book by Hadley Wickham. Here I’ll show the easiest way to do this. If you need to build an entirely – or mostly – new Shiny theme (e.g. a corporate theme), this post is probably not for you. In that case bslib may be the best starting point. Otherwise, if you are generally happy with a pre-made theme and just want to tweak some of its elements, read on.

This post is based on an actual app, so that you can see how it all works. Here’s the app’s source.

Click through to see what kinds of changes you can make without a major overhaul.

Comments closed

Decluttering a Dual-Axis Chart

Amy Esselman only needs one Y axis:

You may be confused and overwhelmed at first. Dual-axis graphs like this are inherently challenging. Whether you call them dual-axis graphs, combo charts, or secondary y-axis graphs, they always demand extra effort from a reader to figure out which data series to read against which vertical axis. 

Click through for a variety of ways to improve a busy dual-axis chart.

Comments closed

Data Visualization Technology Landscape

Andy Kirk has a catalog:

My long-running catalogue of Data Visualisation Resources has for many years been the most-popular, most-visited, and most-referenced content on my website. For the last couple of years, though, it has been a little stagnant with my limited time preventing the frequent updates it needed.

Having recently completed the migration of my website to a new host and undertaken a wide-spread redesign and restructure, it felt an opportune moment to roll up my sleeves and belatedly spend some time pruning the catalogue of out-dated references and introduce all the new ones that I’d encountered, and bookmarked, but not yet added.

Click through for that, as well as the Chartmaker Directory, which gives you an idea of which visuals are available in which products, as well as examples to see them in action.

Comments closed

Creating a Sparkline in the New Power BI Card Visual

Erik Svensen tries out an updated visual:

In the June 23 release of Power BI desktop we has been blessed with a new card visual that not only will give a better performance compared to adding multiple cards in the past but it also gives us some formatting options we have been dreaming of for a long time.

Here is a link to the official blogpost – New card visual | Public preview | Microsoft Power BI Blog | Microsoft Power BI

On social media you have probably already seen a lot of examples of usages, and I wanted to share how you can add a sparkline to the card to make it look something like this.

Erik does a good job of showing off the capabilities of this updated card visual.

Comments closed

Shiny Apps and Fullscreen Behavior

Tim Brock gives us a demo:

Browsers have been implementing variations on a JavaScript fullscreen API for over a decade. Unfortunately, for much of that time the APIs varied across browsers. This made actually using it in production somewhat cumbersome.

Finally, with the release of Safari 16.4 in March of this year, the latest versions of all major desktop browsers now support a single, standardized interface. Legacy versions of Safari for desktop are still in use and there’s still no support at all for the Fullscreen API on iPhones; so while you can cover most users with the standardized API, it should still be for progressive enhancement and not as a fundamental requirement for operation of an application.

Click through for the script.

Comments closed

Using SHAP to Gauge Geographic Effects in R or Python

Michael Mayer runs an analysis:

This is the next article in our series “Lost in Translation between R and Python”. The aim of this series is to provide high-quality R and Python code to achieve some non-trivial tasks. If you are to learn R, check out the R tab below. Similarly, if you are to learn Python, the Python tab will be your friend.

This post is heavily based on the new {shapviz} vignette.

I appreciate the effort to include both R and Python code in this analysis, and recommend you peruse both sets of code listings.

Comments closed