Skip to content

Commit

Permalink
Re-adjust content. Emphasize file system information
Browse files Browse the repository at this point in the history
  • Loading branch information
coatless committed Mar 6, 2024
1 parent aa8d889 commit 344db79
Showing 1 changed file with 51 additions and 26 deletions.
77 changes: 51 additions & 26 deletions include-download-from-url.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)
Expand All @@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -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")
)
Expand All @@ -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")
Expand Down

0 comments on commit 344db79

Please sign in to comment.