I am trying to replicate the code to output an image from output an image with shinylive-r inside a Quarto document.
library(shiny)
library(bslib)
#>
#> Attaching package: 'bslib'
#> The following object is masked from 'package:utils':
#>
#> page
ui <- page_fluid(
imageOutput("image")
)
server <- function(input, output) {
output$image <- renderImage(
{
list(src = "shiny.png", height = "25%")
},
deleteFile = FALSE
)
}
shinyApp(ui = ui, server = server)
#>
#> Listening on http://127.0.0.1:8719
Created on 2025-06-15 with reprex v2.1.1
This works for me with a Shiny app. The image "shiny.png" is in the same directory as "app.R" But I do not know how to get the same results with a code chunk in a Quarto document using shinylive-r
.
I read that the image has to be a base64 encoded file and to be included with
## file: <path name to the base64 encoded file>
## type: binary
I tried to convert the "shiny.png" file with
- a free internet service (Base 64 converter)
base64enc::base64encode()
What were the results of this conversion?
- In the first case, I got a file with the name "encoded-20250615060048.txt". I renamed it to "shiny_logo.txt".
- Alternatively, in the second case, I got a huge string in the console which I copied in a file named "shiny_logo.txt" without the
"
at the beginning and end.
I saved the result as "shiny_logo.txt" in the same directory as "app.R". Then I replaced the line
list(src = "shiny.png", height = "25%")
with
list(src = "shiny_logo.txt", height = "25%")
Rendering the Quarto document, I got the error:
Error in jsonlite::base64_dec(file$content) : Error in base64 decode
.
What follows is the full Quarto document I used:
---
title: "Shinylive Image Test"
format: html
filters:
- shinylive
---
## Display image with shinylive-r
```{shinylive-r}
#| standalone: true
#| viewerHeight: 400
#| components: [editor, viewer]
#| layout: vertical
## file: shiny_logo.txt
## type: binary
library(shiny)
library(bslib)
ui <- page_fluid(
imageOutput("image")
)
server <- function(input, output) {
output$image <- renderImage(
{
list(src = "shiny_logo.txt", height = "25%")
},
deleteFile = FALSE
)
}
shinyApp(ui = ui, server = server)
```
What is wrong? Any help would be appreciated.