## ----setup--------------------------------------------------------------------
#| include: false
library(livelink)


## -----------------------------------------------------------------------------
webr_repl_link("plot(1:10)")


## -----------------------------------------------------------------------------
webr_repl_link({
  data(mtcars)
  plot(mtcars$mpg, mtcars$wt)
})


## -----------------------------------------------------------------------------
script <- tempfile(fileext = ".R")
writeLines(c("# fit a model", "lm(mpg ~ wt, data = mtcars)"), script)

webr_repl_link(script)


## -----------------------------------------------------------------------------
webr_repl_link("hist(rnorm(1000))", autorun = TRUE)


## -----------------------------------------------------------------------------
webr_repl_link("plot(1:10)", panels = c("editor", "plot"))


## -----------------------------------------------------------------------------
webr_repl_link("plot(1:10)")


## -----------------------------------------------------------------------------
app <- "
library(shiny)
ui <- fluidPage(
  sliderInput('bins', 'Bins:', 1, 50, 30),
  plotOutput('hist')
)
server <- function(input, output) {
  output$hist <- renderPlot(hist(faithful$waiting, breaks = input$bins))
}
shinyApp(ui, server)
"

shinylive_r_link(app, mode = "app")


## -----------------------------------------------------------------------------
url <- as.character(webr_repl_link("plot(1:10)"))

preview_webr_link(url)

