Shiny Assistant

Prototype and build Shiny applications with the help of AI
Author

Winston Chang

Published

October 9, 2024

Have you ever had an idea for a great web application with Shiny but felt something holding you back from getting started? Maybe it’s that you don’t know where to start, or that you don’t know which packages use to build the app, or maybe it’s just that you can’t muster the energy to get started. Sometimes you just need a little help to get unstuck.

We’re excited to announce a new addition to the Shiny ecosystem that can help: Shiny Assistant.

Shiny Assistant is a new AI-powered tool that helps you get things done: you can ask it questions about Shiny, or to create a Shiny application from scratch, or ask it to make changes to an existig application. You can think of it as a knowledgeable colleague who is always ready to help out with your Shiny projects, in both R and in Python.

Let’s have a look at a few practical examples of what Shiny Assistant can do. Suppose you want to build an application to calculate mortgage payments. You can just ask Shiny Assistant to build it for you.

“Create an application which calculates mortgage payments.”

Great, we have a working application!

Although Shiny Assistant quickly built an application that works, you are still needed in the loop. It is important to verify the code – you will need to apply your knowledge of the problem domain to check that the application is doing the right thing.

Now that we have something that’s working, we can also ask it to make changes to the application.

“Add a plot which shows the remaining principal on the mortgage.”

Sometimes you know the change that you want to make, and it would be inefficient or complicated to ask Shiny Assistant to make the change for you. In these cases, you can edit the code directly, in the editor panel.

The default values for mortgage amount and interest need a little bit of adjustment to accurately reflect today’s economic conditions. Here we’ll change the code in the editor panel and re-run the application by clicking on the Play button.

Now if we ask Shiny Assistant to make more changes, it will use the code in the editor panel as the basis for further changes – no need to copy and paste your modified code into the chat window.

Notice that when we ask it to add another feature, the updated code keeps the changes to the starting values that we made just above.

“Add an amortization table.”

If you’d like to use this application, here it is with the code editor, and here’s just the application on its own.

Quickly turn ideas into reality

Now that you’ve seen Shiny Assistant in action, here are some applications that it helped build – all in under 5 minutes. Some of these are made with R and some are made with Python.

Linear regression app

CSV viewer

QR code generator

An assistant for Shiny apps

It’s useful to think of Shiny Assistant really as an assistant – it’s there to help you get things done, and it’s fast, and it never gets tired of helping. If you don’t know whether it can do the thing you want, just try asking. We’ve been surprised many times by what Shiny Assistant is capable of doing.

All that said, it doesn’t always get things right. Like a human assistant, it’s imperfect: it makes mistakes, it has gaps in its knowledge, and sometimes in the course of trying to solve a problem, it gets stuck on the wrong path.

When those things happen, you can use the chat to ask it to fix mistakes. For example, if there’s an error that you don’t understand, you can copy and paste the error message into the chat and ask Shiny Assistant to explain and/or fix the problem.

The LLM’s training data is at least few months old as of this writing, so it doesn’t know the absolute latest features in Shiny or other packages. If you find that you need a feature that is newer than the training data, then you can “teach” it by pasting documentation or other examples into the chat.

Shiny Assistant can help with both R and Python – notice the R/Python switch in the upper left.

R/Python Switch

Sharing your applications

After you build an application, you can share it with others in a number of ways.

Shiny Assistant build applications using the Shinylive web interface. Running applications with Shinylive has some important differences from a “normal” Shiny deployment, but one important upshot is that a Shinylive application can be easily shared with others.

What is the difference between Shiny and Shinylive?

Shiny is a web application framework for R and Python. Shinylive is a special build of Shiny which runs R or Python (compiled to WebAssembly) in the web browser, which means that you don’t need a server running R/Python; you just need a web server that can serve up static files.

Because R/Python run in the browser for Shinylive, you only need a “dumb” web server that can serve static files. And it is trivial for the application to scale to a large number of users.

On the other hand, there are some restrictions on what you can do, because of browser security sandboxing, and not all add-on packages can run in the browser. And with Shinylive applications, the code and the data is sent to the user’s web browser, so you can’t keep the code or data secret from the user.

To share an application created with Shiny Assistant, you can simply click on the Share button and then choose to use the Editor URL or the Application URL. The Editor URL includes the editor panel, for those times when you want the user to be able to see and edit the code. The Application URL just shows the application, without the editor. (And with the Application URL, you can hide the blue Shiny header by checking the Hide header checkbox.)

You can use Shiny Assistant at gallery.shinyapps.io/assistant/.

That’s all for Shiny Assistant for now, but we’ll be talking more in the future about how to get the most out of it!