image: thumbnail.jpg
R-Ladies Rome (English) - Interactive R, Python, and Shiny in the Browser with Quarto and Shinylive
🔍 What You’ll Learn
✔️ How Quarto Live brings interactive code to static documents
✔️ How Shinylive allows Shiny apps to run entirely in the browser
✔️ Practical use cases for data science, education, and collaboration
This talk is ideal for data scientists, educators, and open-source enthusiasts who want to make their work more interactive and accessible.
To further explore the subject, we recommend visiting the presentation of the talk : https://ivelasq.github.io/2025-02-21_r-python-shiny-in-the-browser
More about the Speaker:
- https://www.linkedin.com/in/ivelasq/
0:00 R-Ladies Rome Chapter Intro
5:00 Isabella's Talk
Please visit: https://rladiesrome.org
Transcript#
This transcript was generated automatically and may contain errors.
Thanks everyone for joining us. Welcome to R-Ladies Rome. This is our February event. So Raffaella, our organizer, will take care of us.
So I introduce the chapter and then we leave the floor to Isabella Velazquez. Thank you.
Hello everyone. It's a pleasure to have you all here. R-Ladies Rome presents Interactive R, Python, and Shiny into the Browser with Quarto and Shinylive. The speaker we have, Isabella Velazquez.
Exclaimer. This talk is recorded and will be posted on YouTube of R-Ladies Rome. Feel free to turn off your cameras if you don't want to be recorded. Here we ensure safe, inclusive, and harassment-free space is our priority. We are committed to promoting respectful environment where everyone feels welcome to learn, connect, and grow. Please remember that all of our attendees are expected to adhere our code of conduct. Use your chat for introducing yourself and ask questions or raise your hand.
Hello everyone. I'm happy to welcome you to our February event. I'm Rafaela, R-Ladies Rome organizer, and we are thrilled to have you join us today. Get ready for engaging and informative experience. What to expect from this talk? In this talk, Isabella Velazquez will introduce Quarto Live and ShinyLive, tools that enable interactive R in Python and Shiny. Applications to run directly to the browser, no server required. You will learn about create interactive documents, dashboards, and educational content. Expect hands-on demonstration, gain insights on how enhance reproducibility, accessibility, and engagement.
Just to remember to all of us, what is R-Ladies? It's a global community with a mission to promoting the R language for empowering women at all user levels by building a collaborative global network. It was a friendly community founded by 2012 by Gabriela de Queiroz in San Francisco.
And R-Ladies, a local chapter dedicated to promoting inclusivity in R language community. Our monthly meetings provide a platform to discuss the current trends and hot topics in R.
R-Ladies in numbers. R-Ladies Rome has grown into a widely recognized community. Since January, 2023, we have welcomed over 1K members on meetup and gained 2K of RSVPs and successfully organized 25 events.
The founders and organizer of the chapter is Claudio Vitolo, founder, co-founder of R-Ladies Global. And the organizer is Frederica Gasolani and me, Rafael Ribeiro Lucas.
If you are interested in speaking at one of our events or would be like to propose a speaker or a workshop, please scan the QR code and fill up the form. This one, R-Ladies.
And if you'd like to contribute to our chapter and be a co-organizer, we are open to new persons. Please subscribe to the form. And the next future speakers will be Kylie Ansevly, PhD in infectious disease modeling, senior researcher and Claudio Vitolo, scientist and developer in open science advocates related to the story of R-Ladies Global.
So without further ado, we are thrilled to have with us Isabella Velasquez, senior product marketing manager at PositPVC, where she merges content strategy, data analysis and programming to showcase the incredible work happening at Posit. She is passionate about advocate for open source, always exploring new tools to empower data scientists. Today, she will talk about, through part of life and shiny life, showing how we can create fully interactive browser based on R and Python applications without a server. Let's give a warm welcome to Isabella.
Thank you so much for the introduction, Rafael, and thanks to you and Federico for the opportunity. I'm happy to start sharing my screen.
Can you see it okay? All right, and let me get full screen.
All right. Well, hi everyone. Thank you so, so much for being here. I'm really excited to chat with you today about a ton of really, really amazing tools. And I hope that you learned something new today. I know that I certainly did as I was writing out this talk.
And just a quick aside, this is a photo from the James Webb Telescope. We won't be talking about this kind of web today, but another kind of web that I hope you also find very exciting.
Introduction and motivation
As Rafael mentioned, my name is Isabella Velasquez. I'm Senior Product Marketing Manager at Posit, which was formerly RStudio. And one of the things that I absolutely love about working at Posit is that I get a front row seat at the new things that are being developed and being put out for data scientists working in R, Python, or other sorts of languages. And so when Federica reached out about a talk, like I was very excited about this one because I feel like there's so many new capabilities and possibilities that I'm really excited to share with you.
So I am very active on social media. Here's the various links. If you'd like to reach out on LinkedIn or Blue Sky, please do let me know. And with that, let's get started.
So picture this. The first day of class, you have prepared all of your materials, you have your lecture ready, you've sent out the assignment, and then a student comes up to you and says, Professor, I tried installing R, but my laptop keeps running out of space.
Or you're at work and you have created this amazing dashboard that your stakeholders will find extremely valuable. But then you go to your boss and you say, you know, I created this amazing thing, but IT is taking forever to approve the server request. And so you can't share it at that time.
Or another scenario, because your organization doesn't have a server, you're like, okay, well, maybe my colleague and I can collaborate and work on this together and figure out some other way that we can do this. And you send over your GitHub repo to your colleague and they say, I'm sorry, I don't have R set up on my laptop.
And so with all of these different scenarios, you can imagine the idea behind the architecture, the installation, the infrastructure behind needing your languages or your application set up can be quite a barrier to entry for using these really amazing technologies.
can be quite a barrier to entry for using these really amazing technologies.
WebAssembly, WebR, and Pyodide
And so that's why we are entering the world of interactive R and Python in the browser. So running code directly in the browser opens the door for many new exciting uses of data science on the web.
And the two primary technologies that we'll be talking about is, or we'll be talking about several technologies, but these are brought to you thanks to WebR and Pyodide. But before we talk about them, let's talk about another tool called WebAssembly.
So WebAssembly, or sometimes called WASM, is a low-level, high-performance binary instruction and it allows compiled languages like C or C++ to run in web browsers at near native speeds. So C and C++ code is compiled by something called Emscripten. Emscripten takes the C or C++ code as input. It produces WASM as a result. And once it's in WASM, you can run it in any browser that supports WASM, which in modern browsers is actually most of them.
Python has had a browser solution for a while called Pyodide. So what Pyodide does is compiles the Python interpreter CPython to WebAssembly using Emscripten, and then it makes it possible to run Python in the browser.
And relatively more recently, now R has a similar solution with WebR. So WebR is the WebAssembly version of R that has been compiled to run in the browser. It's an open-source project primarily driven by Posit, and thanks to the amazing work of many folks, but especially George Stagg and Lionel Henry, it's now possible to run R code directly in a web browser without the need of traditional servers to execute the code. So essentially what that means is a user can visit a website and run R code directly, so without needing R installed on their device. All that is required is a web host server like Netlify or GitHub Pages.
WebR demo and packages
So let's see what this actually looks like. This is a web-based interactive R console that's included in the WebR source repo as a demonstration of integrating WebR in a wider web application. So it provides a simple R environment in your web browser and includes things like code input, output, code editing, file management, and graphics. So if I click this, this is the URL, and I can share this with others. I could share this with you, and you may notice it kind of looks like RStudio. They did a really nice job designing it so that if you are an RStudio user, it looks very familiar. You have your console down here and your plots here, and even though it looks like RStudio, though, remember, this is completely being run in the browser. There was nothing installed from our end. There was nothing that we had to set up, and I can do something like install packages ggplot2.
Dangerous of live coding. There we go. So it says installing packages, and you'll notice it says downloading WebR package. We'll talk a little bit more about that, but even though it looks familiar, again, everything is being done in the browser. I can go up here into my R script and do library ggplot2, run that, and then I do ggplot ntcars as x equals mpg, ntcars as x equals mpg, y equals hp, plus geom point, and then it produces the plot.
So it's pretty amazing. So say you have somebody, for whatever reason they can't install RStudio, but they really want to learn R, you can send them this URL, and they can try things out on their own.
So in terms of PyDyed, it includes a package manager that allows the use of Python packages. You can also install Python wheels or load custom Python packages with PyDyed. And then on the R side, there's over 14,000 R packages available for WebR. A bit of a caveat. So the way that this works is that R packages have to be compiled for Wasm. That's why the installed package looked a little bit different. And so the 14,000 number comes from 14,000 R packages that were compiled to Wasm without error, but they haven't all necessarily been tested. So again, just a bit of a caveat there, but still a lot of packages are available, especially the ones that are very popular and well-known like tidy models and tidyverse and things like that.
So when you are installing packages, by default, the WebR install function will use the public repository hosted at repos.rwasm.org. And then say like you also want to use your own personal package for use in WebR. So there is a project called R Universe. It's a project by R OpenSci that experiments with ideas for improving the publication and discovery of research software in R. And R Universe builds Wasm binaries for R packages for use in WebR applications. So if you have a custom package, the easiest way to get up and running is to create an R Universe repo for your packages. And then the system will automatically build R binaries for different things, including WebAssembly. And then you can use that in WebR. And so there are other options. There's an rwasm package and things like that, but just wanted to highlight that is the recommended easiest or quickest way to get started.
In terms of how to use WebR, if you go to the WebR documentation linked here,
it's very robust and very detailed. But if you're like me, you look at the front page and it says, install the package, npm i WebR. And you're like, okay. And then import the WebR class. And it has this. And then you realize like, oh, this is JavaScript. So what if you don't know JavaScript like me?
It's the edge. So WebR, it doesn't seem to be as quick and easy to use for those who do. But if you don't, what options do you have? And that is where Quarto comes in.
Introduction to Quarto
Quarto is a next generation open source publishing system. So it is often called the next evolution or the next generation of our markdown. So it's expanded upon our markdown. What we have done at Posit is taken everything that we learned over the past 10 years to develop a system like Quarto.
One of the things about Quarto, it's inherently multilingual. So right now it supports R, Python, Julia and Observable, but it's been designed so that we can add new languages in the future.
Another thing that we've learned is R markdown has a lot of packages that does a lot of things. If you are an R markdown user, you might know like use shringen if you wanna do slides and bookdown if you wanna do books. But Quarto has a shared expression for all these core features. So what that means is if you do a tab set in a Quarto book, it looks the same as a tab set in a Quarto presentation.
And the idea behind Quarto is to create dynamic content with Python and R and Julia and Observable. And then another thing is it enables single source publishing. So the idea of creating notebooks or dashboards or books, et cetera, from one source.
And I will say there are many great resources about Quarto. We're not gonna talk about everything about Quarto. At this time, I'm happy to share the resources. I would say that the Quarto documentation site is absolutely incredible. It is very detailed and how to get started, how to use Quarto. I gave a talk a couple of years ago at R Ladies St. Louis that I'm happy to share that went more into detail in terms of like, you know, getting set up in RStudio and rendering documents and things like that. But for today, I'm just going to be talking about the most critical parts of Quarto that you need to know in order to use WebR and PyEdite in Quarto documents.
Anatomy of a Quarto document
So first, the anatomy of a Quarto document. So a Quarto document has an extension QMD. The first part that we're going to talk about is what is called the YAML heading. So it is denoted by these three dashes and then a key value pairs within these dashes. So the key, for example, can be title and the value is ggplot2-demo.
And the YAML heading contains the metadata for your document. So in this case, it's saying, I want to produce an HTML format. I can provide additional options like code full true means like the code within the document should collapse so that it's not immediately visible unless somebody clicks it to open it up. And so the YAML heading, just to reiterate, is the kind of metadata of your document.
The next part to talk about is the markdown text. So markdown is a lightweight way of writing formatted text and in a way that it looks very readable. You can do things like, for example, here in line eight, the two pound signs mean this is a heading. So this will be rendered as a heading. You can do things like embed images, links, tables, format your text, all sorts of things. But the really nice thing about markdown is that once you learn it, it's easily readable when you say, put it up on GitHub. It doesn't come out in a very nested, difficult to read format. It looks like text.
The next part of the next anatomy of the Quarto document is what are called code chunks. So those are denoted by three back ticks and then in curly braces, the programming language that you want. And within this code chunk is going to be your executable code. So this is code that is actually going to run.
And so there are these things called code chunk options. They're denoted by the pound sign and then the long vertical line. I think that is called a hash pipe. And this provides metadata for your code chunks. So in this case, it's saying label, label this plot, plot penguins. Echo is false means that you do not want to see the actual code chunk. All you want to do is see the output message and warning is if this code produces a message and warning, do not show it. And there are other kinds of things in terms of like handling how things are actually rendered when you render your document from a QMD file to say an HTML document.
And then within the code chunk is your actual code. So in this case, you know, the library, sorry, the packages tidyverse and palmer penguins will run. It will create this ggplot code. And when you click render on this document, that code is actually going to run.
And so this is a quick look of what it looks like when you actually hit render. So all of that, you know, text and code and labels that you wrote is going to output this HTML document that looks like this. If you notice, you can't see the code because you said, please do not show me the code. There's a link and everything like that that came from the markdown text.
Quarto extensions
Another critical part for today are Quarto extensions. So Quarto extensions let you customize and extend Quarto's functionality beyond its built-in features. So things like new output formats, so custom templates for the documents that you want to create. A relatively recent one is the scrolly telling extension. So if you've ever seen those kinds of journalism articles that as you scroll through, they highlight different plots or different parts of a plot or things like that, that is now possible with Quarto thanks to the scrolly telling extension.
Another example is journal articles. So you can install extensions. So if you are trying to say, like submit to the journal statistical software so that your Quarto document renders in the format that they require. Things like reveal.js themes. So presentations in Quarto are done in a format called reveal.js. And there are extensions out there so that you can see, so you can customize what your reveal.js extension will look like. So unique styling and layouts and all sorts of other ways of modifying how Quarto processes content.
So one example that I have is one that I use for the presentation today. So there is a font awesome extension. And how to use extensions is first you install the extension and then a quick note, Quarto extensions, if you go to their GitHub repo or their documentation page, generally have instructions as to how to install it and how to actually use it. So each one might be slightly different, and so you definitely want to go and check their documentation if there is an extension that you want to use.
But for the font awesome extension, you install it, you say Quarto add, Quarto ext font awesome in the terminal. And then in your Quarto document, the YAML heading under, you add a filters option and then list out the different extensions that you want to include. So in this case, filters font awesome.
And then to use the extension of the doc, anywhere that I want to put, say, a GitHub icon, I put this short code with the curly braces. And then when I actually rendered the document, it results in the GitHub icon. So that's an example of a Quarto extension. That being said, there are so many available and here is a link to the Quarto extension gallery by Mikhail Makhnoly. And so if you want to search for different extensions and see what's out there, this is a great place to start.
Another note is that Quarto extensions are Lua-based and if you feel comfortable writing in that, you can also make your own extensions if there is something that you require and you don't see out there in the wild.
Quarto Live extension
So wrapping everything up, we started off talking about WebAssembly and how the technologies behind WebAssembly enable Pyodai and WebR, which allow you to run R and Python in the browser like we saw with the web-based R console. But to use those, you need to know JavaScript. And so we went into a brief introduction of Quarto because with Quarto, there is an extension called Quarto Live.
And Quarto Live allows you to embed WebAssembly-powered code blocks and exercises in Quarto documents through the Quarto Live extension. And there's support for both R via WebR and Python via Pyodai. And features include interactive code blocks, exercises with hints and solutions, and rich output like plots. And the most important thing, WebAssembly and Python skills are not needed to use WebR in your content.
And the most important thing, WebAssembly and Python skills are not needed to use WebR in your content.
And I did also want to briefly mention that originally there was an extension by James Balamuta called Quarto WebR, but Quarto Live is the extension that is supported by Posit.
So let's see what this actually looks like. So Quarto Live, again, embeds these WebAssembly-powered blocks for R or Python into Quarto documents. So after a little bit, you're going to see this editor with a button that says run code.
And if I click this, I have run R code in my browser from a presentation that I created in Quarto. It is pretty amazing. I think it's very cool.
So another thing to note, this is an editor, so I can change whatever I'd like. So say I want to do one through six. Oh, oh, sorry. I don't know what happened. The presentation got, I'm sorry, one second.
Here. I am back. Okay. Okay. Hopefully, if you cannot see it, just let me know. But okay, so I've changed this from one to five to one to six. Let's say print instead of X to the power of two, X to the power of three. We can run code. And then again, it just executes that code in the browser from my presentation.
So in terms of how to actually use this, it's going to look very similar to what we talked about before. First, you install the extension in the terminal, and then you add to your Quarto document YAML header. If you notice, it looks slightly different. So instead of putting it under filters, we put it under format, and we change it from, say, HTML to live HTML.
A quick note is by default, the Quarto live extension uses Pyodied for Python. So if you want to use the Quarto live extension for NIDAR and R, then you have to include the engine, engine NIDAR in your YAML heading. And then you also have to include the shortcode that you see on line six as well.
Then to use Quarto live in a Quarto document, you place your code in either a WebR code chunk for R or a Pyodied code chunk for Python. And so the chunk that you saw a little bit earlier, this is what I have in my document in order to create that live editor that executes code.
A note is you can use Quarto live in your presentations too. So when you're creating a Quarto presentation, you have format reveal JS, and then you edit your YAML header to live reveal JS.
Another cool thing that you can do, say, if you want to use Quarto, sorry, Quarto live in your presentations is you can install the Quarto drop extension. You press the back tick, and then this console for R or Python can drop down. And then again, you can just start typing R code and then execute it in real time. And so you can imagine, say you're giving a lecture, somebody asks like, how would you do this in R? You can just go ahead, drop in R console, try it out, and then lift it up and continue on with your presentation.
In terms of other kinds of options that are included in Quarto live, there are things like you can create breed only cells. So once that you can actually be edited, nope, I didn't realize it's not full screen. You can auto run. So instead of needing somebody to click run code
in order to see the output, you can have it auto run. You can have auto complete within the editor if you want, and much more. So recommend looking at the documentation if you want to see all the things that are possible.
And back to the idea of installing packages, you have a couple options here too. You can install packages as the document loads. So in this case, whenever somebody opens the rendered document, WebR is going to load dplyr, Palmer penguins and ggplot2. And so of course, depending on the size of your packages, it might take a little while. Since I had this presentation already open when we started, there's like a little loading message that lets me know like these packages are being loaded. And so the run code will show up once it's ready to go.
And then another option is interactively. So if you would rather install the packages and load them as you, as your user actually goes through the document, you can include this in your WebR or pylide chunk. And so whenever they click run code, that's when the package will be installed.
Well, a few more examples. We mentioned like WebR and Quarto Live allows you to display plots. So here we have this base R plot. I can click that and then see an example plot. And just a thing to note too, that graphics work a bit different than normal than they do like in regular R. And this is because there's something called a graphics device that implements the drawing commands from R in the browser. But one benefit of this is that it takes advantage of features that exist in browsers already. So things like fonts from other languages or emojis, that's already built in, which is pretty cool.
Let's say I'm seeing this and I'm like, oh, I like this plot. Oh no, I have a typo. I can go ahead, pick that typo, rerun code and get a plot that actually looks the way that I want.
Creating exercises with Quarto Live
Another example is creating exercises with Quarto Live. So you can designate a chunk as an exercise. So this chunk says fill in the blanks so that the result of the sum is 10. I'm like, oh boy, I don't know what to do. I can show a hint and then it tells me consider subtracting one, two, three from 10. I'm like, oh no, I still don't know. Let's say I put five and I click run code. It's going to tell me the output and then let me know that's incorrect. And say I give up, I can say show solution and then it lets me know what the solution is.
So you can imagine for teaching, there's a lot of different kinds of applications. And so here is one from Klaus Wilke on the introduction to R. I open this up. You'll see that Buzzer has created this interactive document. Here is the loading icon. So we know like the packages are not quite ready yet, but it seems like they are being installed as soon as you load the document. And then, okay, it looks like it's ready to go. And then there's all these different exercises that you can go through. And if you imagine there's somebody you're trying to teach introduction to R, here's a great way of making things like really interactive and without like needing that much more to set up beyond the Quarto document that you've created for your lecture.
Another self-promotion that I wanted to give is that I wrote this blog post called Six Not-So-Basic Base R Functions a while back. And a quick note that this used the Quarto WebR extension, not Quarto Live because Quarto Live wasn't quite out yet, but just wanted to show like essentially the same kind of ideas. I wanted to highlight these base R functions and somebody could go in here and run and see like what changes and try things out.
And then also there's an example of what installing packages could look like. So this, for example, is a package that's not on CRAN. It is my older brother's package. And so then I can designate his R universe repository in order to install it and use it in the examples.
I know that that's a lot, but I really hope like this conveys like the excitement and the amazingness that I think this technology brings. And so thanks, Adam, for this note. I hope he's not actually weeping real tears, but it truly is so amazing that sometimes it feels like magic.
but it truly is so amazing that sometimes it feels like magic.
Introducing Shinylive
So we've talked about Quarto documents and executable R chunks and things like that, but you might be wondering, well, what about Shiny? And if you are new to Shiny, Shiny allows you to create web applications without needing to know JavaScript, HTML, or anything like that. You can just do it in pure R or pure Python, which is pretty amazing if you don't know JavaScript like me.
But say you've created your Shiny dashboard, very beautiful, ready to go. And then you need to share it with somebody. So the traditional Shiny architecture for deploying a Shiny app involves a separate server and a client. And we've mentioned the word server several times today, but essentially a server is a machine that's connected to the internet that runs 24 seven ready to run your Shiny app. And the server runs R or Python and Shiny, and clients connect via the web browser. And each client keeps an open web socket connection as long as they are using the application. So this is like probably the simplest way that this works. There are more complex setups, but fundamentally this is kind of what it looks like.
And in terms of hosting Shiny apps, there are a lot of different options for hosting your server. So for example, you can have RStudio server on your laptop and say you need some scalability or additional security for your app, you can get Posit Connect, which is an enterprise version from Posit and for hosting your Shiny apps. There are also cloud-based solutions. Shinyapps.io has been around for a long time. There is a new product called Posit Connect Cloud that lets you publish Shiny and also all sorts of kind of Python frameworks as well. And then like things like Hugging Face, you can roll your own if you would like.
And then in terms of choosing what the right tool is, it's a very wide spectrum in terms of the number of users. For some people, we might just be sharing our apps with one or two other people. For other people, we might be talking thousands. And then there are some folks in between, like a professor, an academic, might have a few hundred folks looking at their apps. But what if you don't have the infrastructure or the resources to set up either of these kind of options?
Another kind of hosting service are web hosting services. And they offer a lot of scalability and features and perhaps a low price point, like GitHub Pages or Netlify or Quarto Pub, but the issue is they can't run traditional Shiny apps. And the reason is that these are called static web hosting. They're very good in terms of reach and affordability. You don't have to think about servers anymore. So when you publish, say, a Quarto website, you just give them your rendered Quarto document files. But there is no way to run Shiny apps on these kind of servers, on these kind of web hosting services.
So if you've ever created a Shiny app before and you've wanted to share it via a website, you've probably had to embed it in an iframe when you wanted to share it. But that is not the only option anymore. Thanks to Shinylive, anybody can create their own serverless Shiny apps to run in the browser.
And in terms of what this looks like, here is a very simple Shiny app. And remember, this is a Quarto presentation, and this is not an iframe. This is embedded in the presentation itself. And this is a Shiny app. So I could change the number, I can change the color, and did not have to host this on any kind of external server. All it is, it's on the web.
So, I'm sorry. Yes, Shinylive was announced in July 2022 for Python, September 2023 for R. And it uses PyDyed and WebR respectively to enable fully in-browser Shiny apps without a backend. And so, in terms of the architecture, all you need to run Shinylive is these static web servers. So when an application is deployed with Shinylive, R or Python and Shiny run in the web browser, the browser is effectively both the client and the server for the application. And that is pretty amazing. So you don't need a separate server to host these apps.
the browser is effectively both the client and the server for the application. And that is pretty amazing.
Ways to use Shinylive
In terms of how to use Shinylive, you have three options. One is the Shinylive online editor. The second is you can convert a Shiny app that you've created traditionally. And the third is you can embed a Shiny app with Quarto.
So there is an online Shinylive editor for R and for Python. So let's open this up. The editor is on the left and you can change this app in real time. So let's let it load. There are several examples here, which is very helpful if you are new to Shiny and you want to see what it looks like and you want to play around with it. Here's the editor and then here is the app. And it's a real app. I can change this. Number of bins change. Similarly, I can change, say, the number of bins. I want the max to be 500. I can rerun the app. And then this, instead of 50, now it's 500. And again, I can move it around and change it. If I were to take this code, say I copy and pasted it into RStudio, as long as I have all the packages installed, it would run. And then I would see this in my viewer pane, for example. And it, again, is one of the ways that you can create a Shinylive app.
In terms of sharing, up here there is a share button and there are actually a couple of options you can use. So say you are working with somebody who already knows R or Python and you want them to work on that same app, you could do it with an editor URL. So it'd look kind of like this. Or say you just want to show it and not allow them to edit, you can share the application URL. You notice it's very long. It's because it contains all the information that is needed in order to create this app on the web, but it's completely shareable. If I sent this to you, you would open it up, say, let's look good at what this looks like, and it would look like this. And then it would load on your browser and you can edit the code and you can play around with the app or anything like that.
Something else I wanted to know is, I saw this question on Blue Sky recently, was should I be using BSLib for creating Shiny apps? And if you have not heard of BSLib before, BSLib is kind of like the next generation package for Shiny creation and styling. And it aims to make these beautiful looking apps right out of the box. So if you've ever heard somebody say like, oh, it looks like a Shiny app and it needs customization and stuff like that, BSLib aims to make it look pretty stunning right off the bat. So all of these are done with BSLib. And so this is also a really great opportunity that if you are new to BSLib, you can kind of see how things are different, how the layout is structured and things like that. And there's a ton of kind of example texts if you wanna try it out.
Going back to our presentation. So the first option was to use the Shinylive Online Editor. The second is you can convert a Shiny app that you've already written. So if you did a dashboard with Shiny for R or Shiny for Python, then you install the Shinylive package. Then you can export the app. So we're using the export function. And this converts the app into a My App directory and produces an output directory site. And it will give you all the files that you would need to give to a static web hosting service in order to see your app. And if you want to, you can also preview the app by running this run static server function. And then it will open up in a web browser. So if you prefer to do something like on RStudio desktop or something like that, and then you want to convert it so that you can put it up on the web somewhere, this is an option for you.
And then the final way that you can create and share Shinylive apps is using the Shinylive extension. So you install the Quarto extension. Again, it should look a little familiar. And then you add it to your Quarto document YAML heading
And then within your Quarto document, you insert a code block with either Shinylive Python or Shinylive Python. Or Shinylive R. And that's it. So like that app that you saw a little bit earlier, this is similar to the code chunk that I put in my presentation in order to create a Shinylive application that I could edit in real time.
Examples of Shinylive in action
A few examples. So one is the Shiny for Python docs. So this is an example of embedding interactiveness in documentation so that people can learn and pick up and iterate just in real time without having to set anything up on their own end. So here is an example with the app.py. You can play around with it and say, I'm new to this, I can start messing around and seeing how things change every time I do this. How things change every time I rerun the app.
There are things like the components. And I mentioned earlier, you know, be a sliv, like say you want to see what a layout looks like by changing things up. You can change it in the app right there, right then.
Another example, again from Classability, is this color picker app. It's just another example of a Shinylive app that's done, that's shared in the browser. So it's shareable through this URL and no server required. So say, you know, this professor has hundreds of students, not enough bandwidth on shinyapps.io to host the Shiny app, but on a web browser, it's absolutely doable. And then it's also an example of a more complex example of a Shiny app. So really, even though it is like more complex and it's doing a lot in the backend and things like that, it's still runnable in the browser.
And the final example that I want to show is Shiny Assistant. So with the admin of AI, there's so many different ways of embedding AI into tools. And this one embeds AI for R or Python through the Elmer package for R or chat list for Python and with Shinylive to create a Shiny Assistant. So this is a chat bot and you can see it says, hello, I'm Shiny Assistant. I'm here to help you with Shiny. Gives you some examples.
And because it's Shinylive, again, completely on the browser, and I can say, could you help me make a really simple Shiny app? And then the editor and the app shows up here on the right-hand side. And so like the docs or examples that you saw earlier, this is totally editable. This is absolutely runnable and say, and because this is a chat bot too, I can go back and forth. And so I can say, could you add another visualization please?
And here on the left, it's going to generate the code. It's going to talk about what it's done. It updates the editor and the app as well. And so as you can imagine, this is a really great way of building prototypes. So BSLib is a really great way of getting started, but say you have a specific layout in mind or something like that, and you don't want to forget a parentheses or something like that. You can work with Shiny Assistant to create the prototype of what it is that you want and get it set up there.
Like before, you can share it so that, you know, somebody can give you feedback or things like that, or say that you've gotten to the point that you don't want to say upload your sensitive data up here, right? Because this is the web. And so instead of what you can do is you can download the project files and then open it up in the editor of your choice so that you can make further modifications and build the exact app with the data that you need. But this is, again, possible thanks to Shinylive and all the advancements that there've been in AI and the integration of AI into different tools. And so if you haven't played around with Shiny Assistant, I highly recommend it. It is how I start with almost every single one of my Shiny apps now.
It is how I start with almost every single one of my Shiny apps now.
Use cases
Okay, so with that, let's talk about some use cases. We've talked a lot about the technology and possibilities and things like that. So let's just kind of outline them. So first of all, it's sharing interactive reports and dashboards with executable code. So with WebR and Pyodide, Quarto Live, Shinylive, it provides a smooth, interactive, immediate introduction to the world of working with data. So users who haven't had the chance to use R due to barriers, but because of software installation or cloud-based service registrations or anything like that can be introduced to R and Python thanks to these interactive examples.
You can also create reproducible documentation through containerization and notebook-style literate programming. And linked here is a article to a Nature post about how WebAssembly is changing how research is shared.
The R Consortium Submissions Group is a group that is working on improved practices of R in clinical trial research. And thanks to Shinylive, they have successfully submitted a pilot R Shiny app featuring Shinylive to the FDA for review.
And in terms of educational benefits, again, say you're doing an intro to R Workshop, you can dive into the code without any software. You can remix examples on the fly. You can have this kind of tactile educational content with interactive experimentation for your students. There's reduced context switching, so they don't have to switch between the console and the tutorial, all in all making the learning process more streamlined and engaging. And then for professors who want to service apps for hundreds of people, but don't have the computational load available to them, this is another use case.
In terms of benefits, this idea of sharing easily, so it shines in accessibility, your content can be hosted on any static web hosting service and you can share it with just a URL. Users can run code without installing software. It can be run on any device or like tablets or mobile. If you haven't seen ThinkR's R Lingo, it's a mobile way of working with R, so if you really want to work with R on your phone.
Things to consider
But there are things to consider and very important kind of decisions that you have to make before deciding on whether you're gonna use Quarto Live and Shinylive. So first thing is that it's under active development and things might change. Some packages are not supported yet. And depending on network access, some might just not work.
Probably most importantly, maybe should have had this as a first bullet, is there are no secrets to the Shinylive apps that's George Stagg. So all the source code goes to the client, all the data goes to the client. And so because everything runs client-side, you want to be careful what you use it for. So be sure to never include credentials, be sure to never include sensors, and never include sensitive data.
And finally, for large data sets, large packages, or really intensive tasks, you want to be cognizant of the performance limitations that might exist. It might just be really, really slow and therefore unusable to some of your audience.
So to sum up a few best practices, you want to keep the computations lightweight and structure code efficiently. You want to offset these kind of performance limitations that could exist. You want to make sure to manage your dependencies correctly. But really, ultimately, it's about choosing the right tool for the job. You know your work best, you know your data best. There might be times where, again, Shiny Assistant is a great time for prototyping and things like that. But if you have a data set with real names, that's when you download it and pull it into something that's nice and secure and airtight.
But if it is something like you're creating exercises, you want to show off some cool functions in a blog post, it might be the right tool, and that is up to you to decide.
So really, it's a very exciting time. I hope that you're excited, too, and have learned some new things today in terms of the future of interactive data science. As Joe Chang said when he announced Shinylive for R at PositConf, truly is we're exploring a new frontier. And there are so many options that you can do in order to leverage these tools in new formats. And these are just examples that I came up with, but I'm sure there's so many other options that I cannot even dream of. And so I'm really excited to see how you take it and run with it.
truly is we're exploring a new frontier. And there are so many options that you can do in order to leverage these tools in new formats.
And with that, thank you. Very open to any questions, and thank you again for joining me.
Q&A
Thank you very much, Isabella. So I have some questions from the chat, I don't know if you have seen them. I have not. Okay, but I asked the audience if you'd like to ask a question directly to Isabella, please raise your hand. While I'm reading these questions that I've read along the way. So the first one was, is there a way to log in and set up an account for the web, so the use of R in the browser?
Hmm, so let me know if I'm answering this correctly. You don't need to log in if you want to set up an account to use WebR, you have to install the packages. And again, you have like the JavaScript kind of option if you know JavaScript, or you have Quarto documents if you want to use that. So all of that, you don't require a login or anything like that. If the question is like, can you set up say a Quarto document with a login to a document with WebR chunks? I believe that is possible. But again, just remember once, you know, somebody gets past that login, all those WebR chunks are still on the web and everything like that. So if it is something that you want to really keep secret or private or anything like that, that you might want to consider some other options.
Okay, so that answers the second question as well. The third one was, does Quarto offer advantages over using Jupyter Notebook for publishing?
Yeah, so I would say, so one advantage, for example, is the one that you saw today. So thanks to the Jupyter Notebook, the one that you saw today. So thanks to the massive universe of extensions that Quarto offers, there are so many things that you could do with Quarto documents that are not possible in Jupyter Notebooks. So if you want to create a document with interactive chunks, you might be able to do that with Pyodide, but not if you're an R user.
And in terms of other kind of advantages, I would say like there's the multilingual aspect. Again, if you are an R and a Python user, you don't have to switch contexts so much to be able to use like different kind of tools. I personally think that Quarto documents are much more readable and user-friendly to use, especially since Jupyter Notebooks have kind of that JSON backend that can be kind of tricky with version control. Quarto, since it's markdown-based, doesn't run into those kinds of issues. And finally, I really like the outputs that Quarto creates. So like the slides that you see here, the websites, the blogs, I just think they look really nice. And I think like there is a huge advantage to be able to present things that look professional and crisp and clear. And I think Quarto really excels in that.
Oop, I think you're unmuted. Oh, sorry. Yeah, thank you for answering the question. So that was interesting to me as well. So I wanted to, there's a full question that says, how would you share your R document with say someone who does not have R?
Yeah, so for example, if you create a Quarto document with R, code chunks, what you would do is you would share, like you would publish that document to say GitHub pages, to Netlify, to some sort of web host server, and then you just share a URL. And so, you know, if I were to share like my blog post, for example, all of that is R. And even if somebody's computer doesn't have R installed
or RStudio installed or any kind of editor installed, all they need is a browser and an internet connection, and then they can run R code.
Q&A: Mixing static and interactive content in dashboards
Great, thank you. Then we have other two questions. I don't know if Eva would like to ask herself. You want to ask directly to Isabella maybe? You can unmute yourself.
So I'm working on a dashboard and some of it is static. And now I would like to have interactive part to it. And I was trying Shinylive already. And is it possible, let's say I prepared the data, I filtered, I added some calculations, and then I want to have, let's say, interactive plot. Can I communicate from within my R chunks to Shinylive chunk, or does the whole thing have to be Shinylive?
Yeah, so I would say you have two options. Since they started with a Quarto dashboard, Quarto dashboards actually do allow using of Shiny components. So say you want to add a sidebar where people toggle between different colors in their plot or something like that, that Quarto can absolutely do that. It is kind of in like Shiny syntax. You have to be like, you know, you need to be familiar with that and things like that.
But the Quarto dashboard guide on the Quarto documentation kind of shows some examples. And there's also a dashboard gallery with some, you know, if you want to pull them up and see their source code and see how they did it. So that's one thing. It's Quarto dashboards with Shiny components.
And then the other option is to create a Shiny app that's hosted on, you know, that is either Shinylive or a traditional Shiny app. And I think like in terms of the consideration of like, which one do you choose? It's one of those things that, again, it depends on you and your data and your audience and, you know, the resources that you have available.
If you don't want to start all over from scratch, I would say like, you know, try out the Shiny components in the Quarto dashboard and see what that's like. Or another option is if you want to try it is to ask the Shiny assistant, right? Like I'm creating this app or dashboard, can you, you know, help me convert it to Shiny code and see how it goes? And that way you have kind of the, like you have like the most options, right? You could do it, you could put it on a website, you can put it on shinyapps.io or whatever it is that you need.
Q&A: Hosting Shiny apps with sensitive data
Yeah, thank you, Isabella. Would you like to ask Isabella directly your question? Sure, thank you, Isabella, for the presentation. It was really helpful. One question I have is I work with sensitive data a lot and we do make dashboards and want to make like, you know, if Shiny live is not the appropriate thing to work with sensitive data, what other servers do you suggest to use? When like we have audiences, outside audiences who wants to look into the dashboard, we don't want them to have the access to any sort of data. What do you suggest?
Yeah, so I would say, I would suggest the ones that are listed in the traditional Shiny architecture page, like the, if you want on-prem, you can spin up your own RStudio server. If it's an enterprise solution, and my company Posit has one that like, it puts everything like behind the firewall. So Posit doesn't have access to the data, only you do, but all the apps are being hosted and, you know, secure and have the computation that they need to run and things like that.
If it is something that say, like the problem with the cloud-based ones is right, like you're still giving, you're uploading your data to something else. And so if it is very sensitive data, I would say like it has to be kind of an on-prem solution. And then Shiny live is definitely not the right one because again, literally everything is sent when you share a Shiny live application.
And then Shiny live is definitely not the right one because again, literally everything is sent when you share a Shiny live application.
Yeah, thank you. Usually like the data sets are smaller. So, you know, we are always like confused, like what to go for, like, you know, buying something like more cloud-based are always not an option for us with student data. So always very confused. Sometimes we do use like Tableau, but again, like you cannot use outputs very easily as you can do with shinyapps.io. But, you know, very confusing, but thank you.
Another option of like on-prem, you know, generally at an organization like IT, you need to set the server and everything like that. One other kind of solution that I've seen is you build like the app itself and say you put data on shinyapps.io or PositConnect Cloud or something like that. But you can also use like a cloud-based solution like shinyapps.io or PositConnect Cloud or something like that, but you don't put the actual data.
So in one of the examples in the Shiny Live documentation, it shows how to like upload a CSV, say, to a shiny app. So you kind of build the structure of a shiny app and then the plot that it would produce, say, from the data, but you don't actually put the data and then you share that app and then people upload their own data, you know, whenever they need to use it. But I would say like the issue with that is like it's not very scalable. The dataset has to be formatted correctly. Like so there are a lot of like kind of roadblocks that could happen if you try to share it that way. And so something that's on-prem is probably, you know, worth it to investigate and set up.
Closing remarks
Oh, I haven't thought about it. Thank you so much.
I don't see any other questions, just a comment from Iris. She said, I've used Markdown and static web pages for search docs and familiar with YAML. So she's happy with these tools and she's done.
Hi, Isabella. Can you hear me? I'm Iris. I've been a technical writer for years and I've used all sorts of tools. I'm very excited about what you presented today in terms of dynamic information and content and the whole interactive part of it. So I look forward to exploring this and see what I can do. I wanted to update my portfolio. And now I have a way to do it. So this is going to be an interesting, juicy project for me.
I'm so glad to hear. And I hope, you know, it's a joyful experience. Thanks very much. Thanks for joining us.
Thanks, Isabella. I know that you're busy now, so we won't take your time away from your busy tasks. So, Raffaella, thank you very much.
We look forward to see many of you to our next event on March. We will let you know soon what is going to happen. And so thanks again, Isabella. Your talk is amazing as always. It's always a pleasure to have you. And so you always give very interesting insights that always says something that, you know, something new, which is very key and very important. So thank you again. And I hope I see you soon. You are all very welcome to join us. And follow us on our social network, please. Follow our Ladies' Room. Bye. Bye now. Thanks all.
