Albert Rapp Profile picture
Dec 14 16 tweets 8 min read
Analytics dashboards are a popular way to explore data or to communicate insights.

So it's good to know how to build one.

Here's how you do that with R in no time. 🧵 #rstats #shiny ImageImage
1 // Data

First, you need data.

It's always fun to work with your personal data, so I will use my the last three months of my Twitter analytics data. You can download yours at analytics.twitter.com

You could also download the public metrics with {rtweet} instead. Image
2 // Data cleaning

Next, do a bit of data cleaning. In my case, I just have to clean the column names and select a few columns.

{janitor} and {dplyr} make that easy. Image
3 // Set up dashboard

Now, we can already start building the dashboard.

Use {shiny} and {bs4Dash} to set up the dashboard. The UI elements from {bs4Dash} make that really simple Image
3b // UI elements from {bs4Dash}

Basically what you need are the modular dashboardXYZ() functions and bs4Cards(). ImageImage
4 // Fill sidebars

Now you can include your data in your app.
Use it to fill the sidebars with sliders.

The easiest way is to write a wrapper around the sliderInput() and use it to fill the sidebar. ImageImage
5 // Add table

The sliders will be used to filter our data. Once it is filtered, we can put it into a table with {reactable}.

This is a 3-step process:

1️⃣ Add reactableOutput() to the UI
2️⃣ Create a reactive for the filtered data
3️⃣ Render table with renderReactable() ImageImage
5b // Table formatting

The table columns could use some formatting. You can do that within the reactable() function.

If you're not familiar with {reactable}, you can just follow along the *many* examples in the excellent docs at glin.github.io/reactable/arti…
6 // Add a box

Adding boxes works on both the UI and the server side.

In the UI, use bs4ValueBoxOutput().

In the server, do two things:
1️⃣ Compute metric summary
2️⃣ Render Value box ImageImage
6b // Repeat for more boxes

You can repeat the same procedure to include more boxes.

The best way to do that is with modules. Since they are best explained in a separate example, I'll just leave this here:
7 // Add interactive plots

Finally, we can add interactive plots with {plotly} using plotlyOutput() + renderPlotly().

And the best part: You don't need to know how {plotly} works. Just make a ggplot and convert it with ggplotly(). ImageImage
7b // Repeat for more plots

Once again, you can repeat the same logic to include more plots with or without modules. The choice is yours.
8 // Reactivity to dark theme

Finally, we need to make sure that the table and the plots react to the dashboard's dark theme toggle.

For the plot, load {thematic} and activate it with thematic_shiny().
For the table, follow the instructions from the docs glin.github.io/reactable/arti…
Yay! 🥳 We've successfully built an analytics dashboard.

Need more details? You can check out the micro-course I've set up for this project.

It comes with code for the completed app and a full video walk-through. You can get it at courses.albert-rapp.de/l/shiny-analyt…
That's a wrap! 🙌

I hope you've found this thread helpful. If you want to see more content like this, follow @rappa753 for more. ☺️

Also, don't forget to Like/Retweet the first tweet below if you can.

See you next time! 👋
If you liked this post, you may enjoy my 3-minute newsletter too.

Every week, my newsletter shares insights on
- dataviz,
- Shiny web apps
- stats

Reading time: 3 minutes or less

You can join at
alberts-newsletter.beehiiv.com/subscribe

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Albert Rapp

Albert Rapp Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @rappa753

Nov 4
I used to think tables are boring.

But they can be beautiful & engaging.

Here's a nice example from @infobeautiful.

It uses many eye-catching elements.

But you don't need catchy visuals to create a great table. Here are a couple of guidelines that will help you 🧵 A huge table describing what needs to be done to the US to z
Let's start with a not so great table and improve it.

Here's a table I would have created just a few months ago.

Not so sexy, right? Let's clean that up. An ugly table describing the number of penguins of different
1. Avoid vertical lines

The above table uses waaaay to many grid lines.

Without vertical lines, the table will look less cramped.

Have a look for yourself. Same table as before but with no vertical grid lines. Table
Read 22 tweets
Nov 3
Some chart types are used all the time. Think:

Box plots
Pie charts
Heat maps
Paired bar charts
Correlation matrix

But just because a chart is used all the time doesn't mean it's good for your use case.

Let's explore some alternatives that may work better for you.
Let's start with something juicy. Here's a pie chart from the Wikipedia page on pie charts.

One major problem with it is that comparisons are hard for e.g. Australia and "Other".

That's a major reason why pie charts are are shunned in the dataviz community. Pie chart showing the relat...
But I do believe that pies are not as bad as some folks make it out to be.

It depends on the purpose. Was the chart intended to highlight mostly the US? Then go for it.

Do you want to compare the other countries too? Then a bar chart would be a safer alternative.
Read 20 tweets
Nov 2
I have 10+ years of university-level education.

But no lecture taught me how to create good visualizations.

These things are crucial for communication but are often not part of the training.

So, let's have a crash course on visualization guidelines anyone can implement. 🧵
1. Know your audience

You can't use the same visualization for every audience.

A plot that works in a scientific journal may bore (or confuse) non-scientists.
2. Know your takeaways

Forget the dream of putting ALL of your great insights into one powerful plot.

This. does. not. work.

If anything, this dream is a gateway to using too many chart types all at once.

Visualize only your most important insights (maybe in separate plots).
Read 17 tweets
Nov 1
There are hundreds of online resources for learning how to code.

But there are much fewer online resources for math.

Maybe that's because LaTeX (the premier math writing tool) isn't good at creating them.

#QuartoPub can do both. So, is it a worthy alternative?🧵 #mathematics
What is Quarto?

Short answer: It's a tool that can create many output formats all from one interface.

That means you can create classical PDF math papers as well as online math books with Quarto.
You may be sceptical about the online part. Maybe you have only seen math in PDF format.

But I assure you that it's a real thing. And it's powerful.

For example, every day hundreds of mathematicians on MathOverflow talk about research-level math online. mathoverflow.net
Read 16 tweets
Oct 23
Paired bar charts suck at comparing values.

Still, they're used all the time because they are easy to make.

But there are better alternatives that are just as easy.

Here's how to create 4 alternatives with #rstats. 🧵
0 // Where's the code?

The code for all plots can be found at albert-rapp.de/posts/ggplot2-…

This thread walks you through the code quickly.
1 // Dot plot

Instead of using bars next to each other, why not points on the same line?

Makes comparison suuper easy.

And it takes only a geom_point() layer. Dead-simple, right?

I think it's even easier to create than a paired bar chart.
Read 17 tweets
Oct 7
Powerful functions can improve your coding experience.

They will save you time and nerves.

Want to learn how to write better functions?

Let me walk you through two advanced #rstats concepts. 🧵
Imagine that you want to count variables in your data set.

I'll use the Palmerpenguins data for demo purposes here.

Check out how your code could look.
Notice how the logic is always the same and only the variable changes?

Let's pour that logic into a function.

Be careful, though. It's not as easy as it looks.
Read 12 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(