diff --git a/include-download-from-url.qmd b/include-download-from-url.qmd index dfb40e2..d2bccb9 100644 --- a/include-download-from-url.qmd +++ b/include-download-from-url.qmd @@ -9,20 +9,26 @@ filters: - shinylive --- -This example demonstrates how we can retrieve and load data from a URL into the R Shinylive app. +This example demonstrates how we can retrieve and load data from a URL into the R Shinylive app. Interested in knowing more? Read on! ## Example App +We'll be exploring the following application: + ```{shinylive-r} #| standalone: true -#| viewerHeight: 400 +#| viewerHeight: 600 ## file: app.R library(shiny) ui <- fluidPage( titlePanel("Hello Shiny!"), - h3("Relative URL"), + h3("Data URL"), verbatimTextOutput("urlText"), + h3("Working Directory"), + verbatimTextOutput("workingDirectory"), + h3("File System Information"), + verbatimTextOutput("fileSystem"), h3("Downloaded Data by Relative URL"), verbatimTextOutput("retrievedData") ) @@ -34,36 +40,25 @@ server <- function(input, output, session) { output$urlText <- renderText({ data_url }) - + output$retrievedData <- renderPrint({ download.file(data_url, "fruit-data.csv") read.csv("fruit-data.csv") }) + output$fileSystem <- renderPrint({ + list.files() + }) + + output$workingDirectory <- renderPrint({ + getwd() + }) } # Create Shiny app ---- shinyApp(ui = ui, server = server) ``` -Interested in knowing more? Read on! - -## Specifying data - -When publishing an R Shinylive application through Quarto, include the `resources` key in the document header with `shinylive-sw.js` and the data file name (e.g., `fruit-data.csv`). - -```md ---- -title: "Your Quarto Page Title" -format: - html: - resources: - - shinylive-sw.js # Required to publish the shinylive service worker - - fruit-data.csv # Required to make sure the data is uploaded alongside the application -filters: - - shinylive ---- -``` ## Data Location @@ -91,13 +86,31 @@ server <- function(input, output, session) { } ``` +## Specifying Data to Publish + +When publishing an R Shinylive application through Quarto, include the `resources` key in the document header with `shinylive-sw.js` and the data file name (e.g., `fruit-data.csv`). + +```md +--- +title: "Your Quarto Page Title" +format: + html: + resources: + - shinylive-sw.js # Required to publish the shinylive service worker + - fruit-data.csv # Required to make sure the data is uploaded alongside the application +filters: + - shinylive +--- +``` + + ## Embedding the R Shinylive in Quarto -Embed the complete R Shinylive app into a `{shinylive-r}` code cell. Ensure to set `standalone: true` and consider adjusting the app height with `viewerHeight: 400`. For example, the standard cell would be: +Embed the complete R Shinylive app into a `{shinylive-r}` code cell. Ensure to set `standalone: true` and consider adjusting the app height with `viewerHeight: 600`. For example, the standard cell would be: ```{{shinylive-r}} #| standalone: true -#| viewerHeight: 400 +#| viewerHeight: 600 ## file: app.R library(shiny) @@ -108,14 +121,18 @@ The full code for the example shown at the top of the document is: ```{{shinylive-r}} #| standalone: true -#| viewerHeight: 400 +#| viewerHeight: 600 ## file: app.R library(shiny) ui <- fluidPage( titlePanel("Hello Shiny!"), - h3("Relative URL"), + h3("Data URL"), verbatimTextOutput("urlText"), + h3("Working Directory"), + verbatimTextOutput("workingDirectory"), + h3("File System Information"), + verbatimTextOutput("fileSystem"), h3("Downloaded Data by Relative URL"), verbatimTextOutput("retrievedData") ) @@ -128,6 +145,14 @@ server <- function(input, output, session) { data_url }) + output$fileSystem <- renderPrint({ + list.files() + }) + + output$workingDirectory <- renderPrint({ + getwd() + }) + output$retrievedData <- renderPrint({ download.file(data_url, "fruit-data.csv") read.csv("fruit-data.csv")