|
| 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