coatless-quarto / r-shinylive-demo Goto Github PK
View Code? Open in Web Editor NEWDeploying an R Shiny Application in Quarto with Shinylive (No Shiny Server Required)
Home Page: https://coatless-quarto.github.io/r-shinylive-demo/
Deploying an R Shiny Application in Quarto with Shinylive (No Shiny Server Required)
Home Page: https://coatless-quarto.github.io/r-shinylive-demo/
Thanks for your work and it is nice.
I've successfully created an app in a local drive \app1.
Now I can run this app using httpuv::runStaticServer("\app1") in R.
Now what should I do so others can view it without R and R server.
In recent months there's been significant development in Quarto Dashboards, and Shinylive integration in Quarto. However, at present, it is not possible to integrate Shinylive specifically within a Quarto Dashboard running a Shiny application.
As Quarto dashboards use a somewhat similar structure to standard Shiny apps, I think integration of this feature in Shinylive would be feasible & extend Shinylive applicability and use cases.
I went to the site "https://quarto.thecoatlessprofessor.com/r-shinylive-demo/", but saw a "Not Found" error in the shinylive app (see screenshot attached). When I tried to render the preview locally by following the steps in the demo, I also had a "Not Found" error on local host.
Hi James, what a nice work that you are doing here! I tried to run the example (following the instructions here and from youtube) but cound´t make it work!
The error log is as following:
Error running Rscript (error code 1): <no output>
`C:/Users/arthur/AppData/Local/shinylive/shinylive/Cache/shinylive-0.2.0` assets directory does not exist.
Using shinylive::assets_ensure()
, it tried to fix the error:
`C:/Users/arthur/AppData/Local/shinylive/shinylive/Cache/shinylive-0.2.0` assets directory does not exist.
Downloading shinylive v0.2.0...
trying URL 'https://github.com/posit-dev/shinylive/releases/download/v0.2.0/shinylive-0.2.0.tar.gz'
Content type 'application/octet-stream' length 254533686 bytes (242.7 MB)
downloaded 147.5 MB
Warning: downloaded length 154707153 != reported length 254533686Warning: URL 'https://objects.githubusercontent.com/github-production-release-asset-2e65be/487125727/7829914b-cc7b-4f3c-8b2d-7ee3cb9c8f70?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20230922%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20230922T173955Z&X-Amz-Expires=300&X-Amz-Signature=a9f86f6726d92c9866607225bcc454843faefa46bce022ac85b5061375f9d86f&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=487125727&response-content-disposition=attachment%3B%20filename%3Dshinylive-0.2.0.tar.gz&response-content-type=application%2Foctet-stream': Timeout of 60 seconds was reachedError in utils::download.file(url, destfile = tmp_targz, method = "auto") :
download from 'https://github.com/posit-dev/shinylive/releases/download/v0.2.0/shinylive-0.2.0.tar.gz' failed
any thoughts?
I can run the below example Shiny app as an app.R
(which pulls in some external data) without any problems, but get "page not found" (404) when attempting to Render
within a Quarto document as a standalone app.
Within the same Quarto document, I have the demo (histogram) example as a second standalone app in a separate {shinylive-r}
chunk and this is rendering correctly, so the Quarto set-up (extension, filter etc.) is working fine.
Any thoughts?
```{shinylive-r}
#| standalone: true
#| viewerHeight: 600
library(shiny)
library(gridlayout)
library(rvest)
library(tidyverse)
library(scales)
library(pageviews)
library(lubridate)
library(bslib)
library(wesanderson)
charts <-
tibble(
chart = read_html(str_c(
"https://en.wikipedia.org/wiki/",
"Category:Statistical_charts_and_diagrams"
)) |>
html_elements(".mw-category-group a") |>
html_text()
)
pv <- function(article) {
article_pageviews(
project = "en.wikipedia",
article,
user_type = "user",
start = "2015070100",
end = today()
)
}
theme_set(theme_bw())
cols <- wes_palette(8, name = "IsleofDogs1", type = "continuous")
ui <- grid_page(
theme = bs_theme(version = 5,
bootswatch = "simplex",
primary = "#9986A5"),
layout = c(
"header header",
"sidebar line "
),
row_sizes = c(
"100px",
"1fr"
),
col_sizes = c(
"250px",
"1fr"
),
gap_size = "1rem",
grid_card(
area = "sidebar",
item_alignment = "top",
title = "Options",
item_gap = "13px",
dateRangeInput("dates",
label = "Date range",
start = "2015-07-01",
end = NULL
),
selectizeInput(
inputId = "article",
label = "Chart type",
choices = charts,
selected = c(
"Violin plot",
"Dendrogram",
"Histogram",
"Pie chart",
"Q–Q plot",
"Error bar"
),
options = list(maxItems = 8),
multiple = TRUE
),
selectInput(
inputId = "scales",
label = "Fixed or free y-axis",
choices = c("Fixed" = "fixed", "Free" = "free"),
selected = "fixed"
),
selectInput(
inputId = "log10",
label = "Log 10 or normal y-axis",
choices = c("Log 10" = "log10", "Normal" = "norm"),
selected = "log10"
)
),
grid_card_text(
area = "header",
content = " Plot Plotter ",
alignment = "center",
is_title = FALSE
),
grid_card_plot(area = "line")
)
server <- function(input, output, session) {
subsetr <- reactive({
req(input$article)
pageviews <- map_dfr(input$article, pv) |>
mutate(
date = ymd(date),
article = str_replace_all(article, "_", " ")
) |>
filter(date >= input$dates[1], date <= input$dates[2])
})
output$line <- renderPlot({
p <- ggplot(
subsetr(),
aes(date,
views,
colour = article
)
) +
geom_line() +
scale_colour_manual(values = cols) +
geom_smooth(colour = cols[7]) +
facet_wrap(~article, nrow = 1, scales = input$scales) +
theme(
legend.position = "none",
axis.text.x = element_text(angle = 45, hjust = 1),
plot.margin = margin(1, 1, 1, 1, "cm")
) +
labs(
x = NULL, y = NULL,
caption = "\nSource: Daily Wikipedia Article Page Views"
)
switch(input$log10,
norm = p,
log10 = p + scale_y_log10(labels = label_number(scale_cut = cut_short_scale()))
)
})
}
shinyApp(ui, server)
```
Hi, thanks for the great demo! I managed to reproduce it following your demo.
I wonder if I can have this feature for every posts in a Blog? Do I need to install the extensions for every posts? Thanks!
I noticed your comments on the service workers not being uploaded and I have been trying to troubleshoot my way through this. I have tried to add the resource explicitly numerous times including:
format:
html:
resources:
- shinylive-sw.js
filters:
- shinylive
project:
type: website
resources:
- shinylive-sw.js
I still get the error in my web browser that the service worker cannot be found. Were there any other suggestions on what to try? Or do you know anything about this being added to the v1.5 milestone? I know you logged the original issue and they assigned it to the milestone but wasn't sure if I missed any updated on that.
Thanks for your walkthrough! It's been very useful.
Thank you for providing this demo. Really useful!
I was wondering if it is possible to show the code alongside the app? Similar to the display.mode = "showcase"
option in runApp()
? I tried it in the shinylive-r
chunk but the app did not render.
I've followed TheCoatlessProfessor and using the steps the following files are created (please see attached file).
But it didn't create shinylivedemo-sw.js. Any idea why. I am using RStudio on Windows 10.
Very exciting to have shinylive for R in Quarto!
Please note, library(bslib)
is needed in step 5 as discovered via quarto-dev/quarto-cli#7370 .
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.