-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
277 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
--- | ||
title: "Joe Cheng's r-shinylive App in a Quarto document!" | ||
format: | ||
html: | ||
resources: | ||
- shinylive-sw.js | ||
filters: | ||
- shinylive | ||
--- | ||
|
||
This document contains just the [Shiny App source code](https://github.com/jcheng5/posit-conf-2023-shinylive/blob/d385ad18eb0d867f25cc4721d9e8c25aeb2dfb90/slides.qmd#L299) used in Joe Cheng's [posit::conf(2023) demo](https://jcheng5.github.io/posit-conf-2023-shinylive/#/option-3-include-1) (Warning: Large file size, don't open on mobile!) | ||
|
||
For a detailed breakdown, please see the <R-shinylive-demo.qmd> file. | ||
|
||
```{shinylive-r} | ||
#| standalone: true | ||
#| viewerHeight: 600 | ||
library(shiny) | ||
# Define UI for app that draws a histogram ---- | ||
ui <- page_sidebar( | ||
sidebar = sidebar(open = "open", | ||
numericInput("n", "Sample count", 100), | ||
checkboxInput("pause", "Pause", FALSE), | ||
), | ||
plotOutput("plot", width=1100) | ||
) | ||
server <- function(input, output, session) { | ||
data <- reactive({ | ||
input$resample | ||
if (!isTRUE(input$pause)) { | ||
invalidateLater(1000) | ||
} | ||
rnorm(input$n) | ||
}) | ||
output$plot <- renderPlot({ | ||
hist(data(), | ||
breaks = 40, | ||
xlim = c(-2, 2), | ||
ylim = c(0, 1), | ||
lty = "blank", | ||
xlab = "value", | ||
freq = FALSE, | ||
main = "" | ||
) | ||
x <- seq(from = -2, to = 2, length.out = 500) | ||
y <- dnorm(x) | ||
lines(x, y, lwd=1.5) | ||
lwd <- 5 | ||
abline(v=0, col="red", lwd=lwd, lty=2) | ||
abline(v=mean(data()), col="blue", lwd=lwd, lty=1) | ||
legend(legend = c("Normal", "Mean", "Sample mean"), | ||
col = c("black", "red", "blue"), | ||
lty = c(1, 2, 1), | ||
lwd = c(1, lwd, lwd), | ||
x = 1, | ||
y = 0.9 | ||
) | ||
}, res=140) | ||
} | ||
# Create Shiny app ---- | ||
shinyApp(ui = ui, server = server) | ||
``` |
Oops, something went wrong.