- 3 Minutes Wednesdays
- Posts
- 3MW (HTML & CSS for R users? Why?)
3MW (HTML & CSS for R users? Why?)
Guten Tag!
Many greetings from Ulm, Germany.
It's easy to think that R users do not need HTML & CSS. After all, R is a language designed for data analysis, right? But the reality is that these web standards are everywhere, even in R.
In today's newsletter, we're going to talk about four popular R tools where you can definitely benefit from understanding these languages.
But before we begin, one announcement w.r.t. to the premium part of this newsletter: It was always a challenge to strike a balance between the free and premium parts of the newsletter. I wanted to provide valuable content for everyone while also offering something extra for those who supported me through the premium subscription.
However, it was always a struggle to cut the newsletter into two parts without removing essential information from the free section and without making the premium section mundane. After testing this for two months, I have come to the conclusion that it's too draining to find this balance. Hence, I’m canceling the premium part. If you want, you can still support my work financially with a coffee.
Now, let’s dive into the newsletter.
Text colors with {ggtext}
Here, have a look at this dataviz:
Instead of using a separate legend, it colorizes words in the title. This way, it becomes clear which color refers to what. In R, you can create such a title with {ggtext}
. There are two steps for this:
Create a title that uses
span
-tags. That’s HTML & CSS right there!Activate HTML & CSS with
element_markdown()
intheme()
.
Tables with {gt}
You can create beautiful tables in R with {gt}. While it is possible to use {gt} without any knowledge of HTML & CSS, there are at least two instances where this knowledge can come in handy.
Debugging: You can use the web developer view of your web browser to inspect the source code of the table and identify any issues or errors, such as missing borders or incorrect formatting.
Cool CSS features: HTML & CSS can help you access cool features such as color gradients and hover animations, allowing you to create even more visually appealing tables.
Quarto is a web dev gateway drug
Quarto is a powerful tool for creating beautiful and interactive documents. I think of it as a gateway drug to web development: While it offers a user-friendly interface for creating documents and blogs, it also allows users to delve into the world of HTML & CSS without even realizing it.
For example, trying to change the appearance of your blog, will immediately end up in you fidgeting with the HTML/CSS code:
But even if you want to use features such as the grid-layout, you will write code like this:
Spoiler: This only mimics HTML div tags of the grid class. This code becomes much more understandable once you understand that.
Customized app with {shiny}
Shiny lets you create interactive web applications in R without the need for knowledge of HTML and CSS. However, even a basic understanding of these web standards can be incredibly useful.
For example, you can use HTML and CSS to customize various aspects of your Shiny application, such as the appearance of input elements like buttons or text boxes. That’s because each input uses the ...
operator to accept HTML and CSS. This allows you to easily add custom styles to your inputs without needing to be an expert in CSS.
Don’t believe me? Here’s an easy example. Take a look at the code for a button in Shiny.
Now let’s inject a short line of CSS:
Cool, our button looks different now. As you can see, you don’t need to be an CSS expert to personalize your app like that.
That’s a wrap. Hope you’ve enjoyed this week’s newsletter and will give HTML & CSS a shot now. Let me know if you have any questions or if you just want to share feedback.
See you next week!
Albert 👋
Reply