Skip to content

Using LLMs in Shiny (for R & Python): The Shiny Side of LLMs

You might have seen The Shiny Side of LLMs pop up on the Shiny blog, which is my latest three-part blog series written for anyone who wants to understand what large language models (LLMs) actually do, and how to use them in a Shiny app. It’s a complete (mini?) guide on how to work with LLMs in both Python and R.

Why I wrote this series

Before we jump into the summaries, here’s a bit of background on why I wrote it.

When I started exploring LLMs, I found the online explanations either too high level or way too complicated. Often they were full of mysterious jargon and missing the “why”.

As I wrote on LinkedIn:

I don’t like things to be boring or overly complicated. And in the fast-moving world of LLMs it’s easy to get lost in all the mysterious jargon. I prefer plain English, a bit of humor (if I may say so 😂), the occasional silly comment, and examples that are actually useful.

That’s exactly what I tried to capture in this series. My goal? Help you build a solid understanding of LLMs, and use that to create an awesome Shiny app. In both R and Python 💙.

No need to know anything about model hosting, clusters, or fancy acronyms. Just you, some R or Python, and a fun idea.

The Shiny Side of LLMs: blog summaries

If you’re new to the series, here’s a quick overview for each part. It’s written as a story (spoiler alert: building an app called DeckCheck), but you can easily jump in without having read the series from start to finish.

Part 1 - What LLMs Actually Do (and What They Don’t)

In part 1, I discuss what LLMs really are, beyond the hype and buzzwords. It covers:

  • What “large”, “language”, and “model” actually mean.
  • How LLMs generate text (token prediction, context windows, embeddings).
  • Why they sometimes hallucinate or make mistakes.
  • How retrieval-augmented generation (RAG) fits into this story.

It’s the friendly foundation you need before writing any code. Just plain English, a few jokes, some aha-moments, and enough detail to make you full understand what people are talking about.

Spoiler alert: it’s not so magic after all.

📚 Read it here: The Shiny Side of LLMs: Part 1

Part 2 - Talking to LLMs: From Prompt to Response

In part 2, we get more practical. This post covers how to talk to LLMs. It’s not just theory, but actual R and Python code. In this part we’ll take a look at how to let an LLM analyse your Quarto slides, and give actionable suggestions for improvements.

You’ll learn how to:

  • Set up an LLM client using chatlas and ellmer.
  • Craft prompts that lead to consistent, useful answers.
  • When to use system prompts and users prompts
  • The best way to input data into an LLM
  • Handle structured outputs, errors, and streaming.
  • Use tools and get into “tool calling” territory.

By the end, you’ll go from “Hey, ChatGPT” to “I can call an LLM programmatically, parse the output, and actually use it in my code”.

📚 Read it here: The Shiny Side of LLMs: Part 2

Part 3 - Build Your First LLM App with Shiny for R or Python

Finally, part 3 ties it all together! In the last part of the series we’ll build a Shiny app from start to finished. The app is called DeckCheck and it analyses your Quarto slides. We build a user interface (UI) that lets our users easily upload their slides, provide some input, and eventually spot areas for improvements. It’s all powered by an LLM.

If you follow the steps in this part, you’ll:

  • Build a simple chat interface.
  • Connect your app’s UI and server logic to the model’s input/output loop.
  • Learn how to process model responses asynchronously.
  • Make sure your users don’t get bored by providing a custom loading experience (heyyyy, bouncing robot!).
  • Handle errors gracefully and keep things safe and efficient.

By the end, you’ll have something real: a Shiny app that talks to an LLM, understands your data, and feels personal and interactive.

📚 Read it here: The Shiny Side of LLMs: Part 3

Wrap up

So that’s The Shiny Side of LLMs! It’s a mix of tech, curiosity, and (hopefully) a few smiles along the way.
Whether you read it start to finish or just jump into the parts that fit your project, I hope it helps make LLMs feel a little less mysterious and a lot more useful. And it doesn’t matter if you are a Python user, an R user, or both. The examples are always written in both Python and R!

☕ Fair warning though: grab a coffee or two before you start. I’m thorough, and I don’t do half-baked explanations 🙃.

Leave a Reply

Your email address will not be published. Required fields are marked *