Skip to content

Commit 8b561ae

Browse files
authored
Add github page with demo app (#14)
* Add demo app and gh-page workflow * build on push * Upload site artifact * deploy on main
1 parent 603a4e2 commit 8b561ae

3 files changed

Lines changed: 123 additions & 3 deletions

File tree

.github/workflows/deploy-app.yaml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Workflow derived from https://github.com/posit-dev/r-shinylive/blob/main/.github/workflows/deploy-app.yaml
2+
name: deploy to gh-pages
3+
4+
on:
5+
workflow_call:
6+
inputs:
7+
cache-version:
8+
type: string
9+
default: "1"
10+
required: false
11+
push:
12+
branches: ["main"]
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
env:
18+
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
19+
R_KEEP_PKG_SOURCE: yes
20+
21+
steps:
22+
- uses: actions/checkout@v4
23+
24+
- uses: rstudio/shiny-workflows/setup-r-package@v1
25+
with:
26+
packages: |
27+
renv
28+
posit-dev/r-shinylive
29+
sessioninfo
30+
cache-version: ${{ github.event.inputs.cache-version }}
31+
32+
- name: Find package dependencies
33+
shell: Rscript {0}
34+
id: packages
35+
run: |
36+
# Find package dependencies using {renv} and install with {pak}
37+
pak::pak(
38+
unique(renv::dependencies("./editbl")$Package)
39+
)
40+
41+
- name: Build site
42+
shell: Rscript {0}
43+
run: |
44+
shinylive::export("./demo", "site")
45+
46+
- name: Upload site artifact
47+
if: github.ref == 'refs/heads/main'
48+
uses: actions/upload-pages-artifact@v3
49+
with:
50+
path: "site"
51+
52+
deploy:
53+
if: github.ref == 'refs/heads/main'
54+
needs: build
55+
56+
# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
57+
permissions:
58+
pages: write # to deploy to Pages
59+
id-token: write # to verify the deployment originates from an appropriate source
60+
61+
# Deploy to the github-pages environment
62+
environment:
63+
name: github-pages
64+
url: ${{ steps.deployment.outputs.page_url }}
65+
66+
# Specify runner + deployment step
67+
runs-on: ubuntu-latest
68+
steps:
69+
- name: Deploy to GitHub Pages
70+
id: deployment
71+
uses: actions/deploy-pages@v4

.gitignore

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/editbl.Rcheck/
22
editbl_*.tar.gz
3-
4-
5-
3+
.site
4+
.Rbuildignore

demo/app.R

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
library(shiny)
2+
library(editbl)
3+
4+
ui <- fluidPage(
5+
tags$h1('editbl - demo'),
6+
br(),
7+
editbl::eDTOutput('data'),
8+
verbatimTextOutput('modifiedData'),
9+
helpText('Note different behavior of different data types.'),
10+
helpText('Edit cells by clicking the in-row buttons or directly within the table.'),
11+
helpText("See how 'id' is generated on the fly."),
12+
helpText("Note how only 'city_id' is stored even if not displayed. Cities are a separate table with foreign key."),
13+
)
14+
15+
server <- function(input,output,session){
16+
superheroes <- data.frame(
17+
id = sapply(1:3, uuid::UUIDgenerate),
18+
first_name = c('Bruce', 'Tony', 'Clark'),
19+
last_name = c('Wayne', 'Stark', 'Kent'),
20+
first_appearance = as.Date(c('1939-03-30', '1962-03-15', '1938-04-18')),
21+
publisher = as.factor(c('DC Comics', 'Marvel', 'DC Comics')),
22+
cars_owned = c(5,17,1),
23+
city_id = c(1,2,3)
24+
)
25+
26+
cities <- data.frame(
27+
city_id = c(1,2,3),
28+
name = c('New York', 'Gotham City', 'Smallville'),
29+
country = c('US', 'US', 'US')
30+
)
31+
32+
33+
modifiedData <- editbl::eDT(
34+
id = 'data',
35+
data = superheroes,
36+
foreignTbls = list(foreignTbl(superheroes, cities, 'city_id')),
37+
options = list(columnDefs = list(list(visible=FALSE, targets=c("id","city_id")))),
38+
defaults = dplyr::tibble(id = uuid::UUIDgenerate())
39+
)
40+
41+
output$modifiedData <- renderPrint({
42+
data <- modifiedData$state()
43+
print(str(data))
44+
print(data)
45+
}
46+
)
47+
48+
}
49+
shiny::shinyApp(ui,server)
50+

0 commit comments

Comments
 (0)