-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch over to a site to show approaches.
- Loading branch information
Showing
5 changed files
with
127 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,31 @@ | ||
project: | ||
title: "R-shinylive-embed-data-with-file" | ||
type: website | ||
output-dir: _site | ||
|
||
website: | ||
title: "Data inclusion in a shinylive app" | ||
search: true | ||
reader-mode: true | ||
sidebar: | ||
style: "floating" | ||
contents: | ||
- href: index.qmd | ||
text: Home | ||
- href: include-file.qmd | ||
text: File Embed in App | ||
- href: include-download-from-url.qmd | ||
text: Download file into App | ||
|
||
page-footer: | ||
left: "Data in shinylive apps" | ||
right: | ||
- icon: github | ||
href: https://github.com/coatless-tutorials/r-shinylive-data-include | ||
|
||
# Set the language that should be used for Quarto websites | ||
# https://github.com/quarto-dev/quarto-cli/tree/main/src/resources/language | ||
# lang: en | ||
|
||
# Attach shinylive to every page | ||
filters: | ||
- shinylive |
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,46 @@ | ||
--- | ||
title: "Use Data by Downloading it into the R Shinylive App" | ||
format: | ||
html: | ||
resources: | ||
- shinylive-sw.js | ||
- fruit-data.csv | ||
filters: | ||
- shinylive | ||
--- | ||
|
||
```{shinylive-r} | ||
#| standalone: true | ||
#| components: [editor, viewer] | ||
#| layout: vertical | ||
#| viewerHeight: 400 | ||
## file: app.R | ||
library(shiny) | ||
ui <- fluidPage( | ||
titlePanel("Hello Shiny!"), | ||
h3("Relative URL"), | ||
verbatimTextOutput("urlText"), | ||
h3("Downloaded Data by Relative URL"), | ||
verbatimTextOutput("retrievedData") | ||
) | ||
server <- function(input, output, session) { | ||
data_url <- "https://https://tutorials.thecoatlessprofessor.com/r-shinylive-data-include/fruit-data.csv" | ||
output$urlText <- renderText({ | ||
data_url | ||
}) | ||
output$retrievedData <- renderText({ | ||
download.file(data_url, "fruit-data.csv") | ||
read.csv("fruit-data.csv") | ||
}) | ||
} | ||
# Create Shiny app ---- | ||
shinyApp(ui = ui, server = server) | ||
``` | ||
|
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,42 @@ | ||
--- | ||
title: "Include Data By Embedding File Contents Inside Code Cell" | ||
format: | ||
html: | ||
resources: | ||
- shinylive-sw.js | ||
filters: | ||
- shinylive | ||
--- | ||
|
||
```{shinylive-r} | ||
#| standalone: true | ||
#| components: [editor, viewer] | ||
#| layout: vertical | ||
#| viewerHeight: 400 | ||
## file: app.R | ||
library(shiny) | ||
ui <- fluidPage( | ||
titlePanel("Hello Shiny!"), | ||
verbatimTextOutput(outputId = "dataVariables") | ||
) | ||
server <- function(input, output) { | ||
output$dataVariables <- renderPrint({ | ||
ds <- read.csv("fruit.csv") | ||
ds | ||
}) | ||
} | ||
# Create Shiny app ---- | ||
shinyApp(ui = ui, server = server) | ||
## file: fruit.csv | ||
id,name,count | ||
1,"apple",20 | ||
2,"orange",12 | ||
3,"grape",100 | ||
``` | ||
|
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