Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editable participants #59

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

allenmichael099
Copy link
Contributor

Working on allowing deployers to label recommendations for participants. Currently the recommendation for every participant will be 'unknown' . The plan is to add the object ID from Stage_Profiles to the participants table, hide it from view, and use it to add recommendation fields to documents in Stage_Profiles.

The ability to create new labels using selectize is made possible using DavidPatShuiFong's 'develop' branch of DTedit.

@allenmichael099 allenmichael099 marked this pull request as draft July 26, 2021 02:29
@allenmichael099
Copy link
Contributor Author

allenmichael099 commented Aug 3, 2021

To make participants editable with the ability to create labels, I cloned DavidPatShuiFong's DTedit and switched to the 'develop' branch. Then I have to load his branch and load emdash. Unfortunately, the data download buttons do not appear for participants or in Bike Check In.

Here are the warnings I get:

devtools::load_all('C:/Users/mallen2/DTedit_David_Fong')
devtools::load_all(".")
i Loading emdash
Warning messages:
1: replacing previous import ‘DTedit::dataTableOutput’ by ‘shiny::dataTableOutput’ when loading ‘emdash’
2: replacing previous import ‘DTedit::renderDataTable’ by ‘shiny::renderDataTable’ when loading ‘emdash’

While the app is running:

Warning in processWidget(instance) :
renderDataTable ignores ... arguments when expr yields a datatable object; see ?renderDataTable
Warning in processWidget(instance) :
renderDataTable ignores ... arguments when expr yields a datatable object; see ?renderDataTable
Warning: `autoHideNavigation` only works with DT client mode and it will be ignored

@allenmichael099
Copy link
Contributor Author

@allenmichael099
Copy link
Contributor Author

allenmichael099 commented Aug 3, 2021

Somehow DTedit correctly displays the download buttons in the Fix bike check in branch, but does not in this branch.
Also, the renderDataTable ignores ... warnings are because DTedit (David Fong's master and develop) sends extra arguments to renderDataTable, but we need "filter" and "extensions" sent to the datatable function.

@allenmichael099
Copy link
Contributor Author

Below is a reproducible example of the download buttons not appearing, with commented samples from Fix Bike Check In.

#library(DTedit)       # Load DavidPatShuiFong's DTedit 
mod_DTedit_ui <- function(id) {
  ns <- NS(id)
  dteditmodUI(ns('my_cars'))
}

mod_DTedit_server <- function(input, output, session, data_for_table) {
  ns <- session$ns 
  req(data_for_table)
  
  insert_callback <- function(data, row) {
    data_template <- data.frame(speed = NA, dist = NA)
    data <- rbind(data, data_template)
    return(data)
  }
  
  update_callback <- function(data, olddata, row) {
    data_for_table[row,] <<- data[row,]
    # in this case, 'mydata' should just be the same as 'data'
    return(data_for_table)
  }
  
  delete_callback <- function(data, row) {
    return(data[-row, ])
  }
  
  DT_options <- list(
    scrollX = TRUE,
    pageLength = 5,
    dom = "Bfrtip",
    buttons = c("copy", "csv", "excel", "pdf", "print", "colvis")
  )

  # As seen in Fix bike check in app_server  
  # datatable_options <- list(
  #   scrollX = TRUE,
  #   pageLength = 50,
  #   dom = "Bfrtip",
  #   buttons = c("copy", "csv", "excel", "pdf", "print", "colvis")
  # )
  
  return_values <- callModule(
    DTedit::dteditmod,
    id = 'my_cars',
    thedata = data_for_table,
    edit.cols = c("dist",'speed'),
    view.cols = c("speed","dist"),
    callback.update = update_callback,
    callback.insert = insert_callback,
    callback.delete = delete_callback,
    # filter = list(position = "top", clear = FALSE),
    # extensions = "Buttons",
    
    datatable.options = DT_options

  )
  
  # As seen in Fix Bike Check In mod_DTedit
  # return_values <- callModule(
  #   DTedit::dteditmod,
  #   id = "DTedit_table",
  #   thedata = table_data,
  #   edit.cols = edit_columns,
  #   view.cols = column_names[!column_names %in% '_id'], # view the table without the '_id' column
  #   callback.update = update_callback, # db operations defined in utils_update_insert_delete.R
  #   callback.insert = insert_callback,
  #   callback.delete = delete_callback,
  #   show.insert = allow_insert,
  #   show.update = allow_update,
  #   show.delete = allow_delete,
  #   show.copy = FALSE,
  #   label.delete = "Delete Row",
  #   datatable.options = DT_options
  # )
}

ui <- function(id) {
  fluidPage(mod_DTedit_ui("Table"))
}

server <- function(input, output, session) {
  bike_data <- cars
  callModule(module = mod_DTedit_server,
             id = "Table",
             data_for_table = bike_data)
}

shinyApp(ui, server)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant