3MW ({epoxy} meets {shiny} ❤️)

Guten Tag!

Many greetings from Ulm, Germany. Last week, we took a look at the very cool {epoxy} package. I showed you how it can be used to make text formatting easier. But the really cool thing is that you can use epoxy’s syntax for your Shiny apps too.

Let's have a look how that works. But first, let me throw in my regular announcements. This week, I got A LOT of exciting things to share.

No time for dataviz?

Ever had the feeling that creating an insightful dataviz might take too much time? I know that it can certainly take huge amounts of time to tweak little things in a chart.

But the basics that will get you very far can be achieved in just a couple of minutes. My newest YT video shows you how to create a decent chart in a short amount of time.

Course progress

My dataviz course is making progress. This week, I added a first set of lessons on how to give your reader context fast. Check out the transformation I will teach you.

I’ll likely start inviting a couple of people to beta-test these lessons this week. If you’re interested in joining, then sign up for the course mailing list. I will select beta-testers from there.

Tables, tables, tables

Speaking about video courses: My video course “Making Beautiful Tables with R” was released last week. Check out the course (and promo video!) on the R for the Rest of Us Website.

Now let’s dive into the newsletter. As always, you can find the full code on GitHub.

Shiny + Epoxy

Last week, we learned about epoxy_html() which required a {{ }} syntax. You can use that syntax for your Shiny apps too. That’s really useful if you want to display text based on a reactive. For example, you could wrap multiple UI-elements into ui_epoxy_html() like so:

Here, the placeholders title, year, director and rated have to be filled using a render_epoxy() call. Notice that we can also add HTML markup. So instead of using @bold to make the output bold (like we learned last week), we have to use strong because that means the output will be wrapped in <strong></strong> tags.

Now, to render the output, use render_epoxy() that provides a list (in this case a tibble) of values for the placeholders.

Here, movie() is a reactive expression containing a tibble with column names matching the placeholders.

This reactive expression can be linked to a dropdown input so that you get a dynamic UI like this:

Of course, you can wrap not only stuff like p(), h2(), etc. into ui_epoxy_html(). You can also use arbitrary inputs like sliderInput().

Use Markdown for long texts

Finally, let me mention that writing long texts with ui_epoxy_html() may be tedious. Instead, you can use ui_epoxy_markdown() to write everything based on Markdown.

For example, you could transform our previous UI as follows:

But of course, this might me messy. To make it a bit easier on your UI code, put that Markdown stuff into a new Markdown file and load it with includeMarkdown().

And just like we mentioned before: If you need to add more styling than what Markdown can give you, then you can throw in custom CSS classes that you can style individually. For example, you could modify your Markdown file to include a class .red_class to the title.

And in your app, you could include the style with a seperate CSS file. But for a demo case like this, you can just add it inline.

So that should give you an impression of how you can combine {epoxy} and {shiny} to make your life easier. Check out the other instructive examples that run_epoxy_example_app() can show you. The cool thing about this is that you will get to see the Shiny code as well as the app next to each other.

Hope you’ve enjoyed this week’s newsletter. If you want to reach out to me, just reply to this mail or find me on Twitter, uhhh I mean X. More recently, you can also find me on LinkedIn.

See you next week,
Albert 👋

If you like my content, you may also enjoy these:

Reply

or to participate.