I have a data table with data like these:
On a given DAY, multiple shops (SHOP) are visited and the number of products with high (RED_VAL), moderate (YELLOW_val) and low (GREEN_VAL) prices is recorded. Then the total no. of products per shop is calculated in col. TOT.
I want to display the data like this:

Thus, sort them in two tables, with the first showing the days and the shops, and the second one all the other data. The second one should be edittable (allowing row modification and additions/ deletions). The first table should then be notified of any changes (ie in the SHOP col). Also, the TOT col. should be automatically updated, following any changes in the (*_VAL) columns.
My code looks like this so far:
library("dplyr")
library("shiny")
library("DT")
library(DTedit)
library(dplyr)
df <- data.frame(
DAY = c("day1", "day1", "day1", "day4", "day4","day6", "day6", "day8", "day8", "day8"),
SHOP = c("shop1", "shop2","shop3", "shop1", "shop2", "shop6",
"shop7", "shop8", "shop9","shop10"),
TOT = c(16, 19, 22, 25, 28, 31, 34, 37, 40, 43),
GREEN_VAL = c(3,4, 5, 6, 7, 8, 9, 10, 11, 12),
YELLOW_VAL = c(5, 6, 7, 8, 9,10, 11, 12, 13, 14),
RED_VAL = c(8, 9, 10, 11, 12, 13, 14, 15,16, 17))
# create a summary table
summary_df = df %>%
group_by(DAY) %>%
summarize(SHOPS = paste(SHOP, collapse = ','))
ui <- fluidPage(DT::dataTableOutput("yy")
, DT::dataTableOutput("kidd"))
server <- function(input, output) {
# display the data that is available to be drilled down
#parent
sum1 <- dtedit(input,
output,
name = 'summary',
thedata = (summary_df))
output$yy <-
DT::renderDataTable(
datatable(
sum1$thedata,
extensions = 'Buttons',
filter = "top",
selection = "single",
editable = T,
options = list(
autoWidth = TRUE,
dom = 'Blfrtip',
buttons = c('colvis', 'copy', 'csv', 'excel', 'pdf', 'print')
)
)
)
# for selected row... get child
observeEvent(input$yy_rows_selected, {
selected_days <-
summary_df[as.integer(input$yy_rows_selected), ]$DAY
drilldata = df[df$DAY %in% selected_days, ]
# display child
kid <- dtedit(input,
output,
name = 'summary',
thedata = drilldata)
output$kidd <-
DT::renderDataTable(
datatable(
kid$thedata,
extensions = 'Buttons',
filter = "top",
selection = "single",
editable = T,
options = list(
autoWidth = TRUE,
dom = 'Blfrtip',
buttons = c('colvis', 'copy', 'csv', 'excel', 'pdf', 'print')
)
)
)
})
}
shinyApp(ui, server)
Many thanks for your time!!!