-
Notifications
You must be signed in to change notification settings - Fork 182
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
(enhancement) add checkbox to DT #20
Comments
Please see http://rstudio.github.io/DT/shiny.html and let me know if there is anything that you want me to improve or change. Thanks! |
@yihui Perhaps I'm missing something, but I am not able to make this work for me. Sadly this nullify the checkbox: as soon as the new value is entered the checkbox is lost / not-persisted: this means for example that I cannot use sliders etc. Is there a way to update the datatable preserving the checkbox? library(shiny)
library(DT)
df_ <- data.frame(col1 = as.numeric(11:22), col2 = 1:12,
col3 = 31:42, mth = month.abb,
stringsAsFactors = F)
runApp(list(
ui = fluidPage(
fluidRow(
column(1, actionButton("loadButtn", label="Load")),
column(6, DT::dataTableOutput('dtTb')),
column(3, uiOutput("outSel"))
)
),
server = function(input, output, session) {
output$dtTb <- DT::renderDataTable({
if(input$loadButtn ==0) return()
if(! is.null(input$dtTb_selected)) {
isolate({
index <- input$dtTb_selected
picked <- month.abb[index]
loop <- length(picked)
buttn <- 1
}) # end isolate
vals <- sapply(1:loop, function(i) {
if(is.null(input[[paste0(picked[i],buttn)]] )) {
0
} else {
as.numeric(input[[paste0(picked[i],buttn)]])
}
})
df_$col2[which(df_$mth %in% picked)] <- vals
}
DT::datatable(df_, rownames = checkboxRows(df_),
escape = -1,
options=list(
deferRender = TRUE,
autoWidth = FALSE,
searching=F
))
})
####
output$outSel <- renderUI({
if (length(input$dtTb_selected)==0) return()
index <- input$dtTb_selected
picked <- month.abb[index]
buttn <- 1
loop <- length(picked)
valsTv <- sapply(1:loop, function(i) {
if(is.null(input[[paste0(picked[i],buttn)]])) {
0
} else {
as.numeric(input[[paste0(picked[i],buttn)]])
}
})
toRender <- lapply(1:loop, function(i) {
sliderInput(inputId = paste0(picked[i],buttn),
label = h6(paste0(picked[i],"")),
min = 0,
max = 10,
step = 1,
value = as.numeric(valsTv[i]) ,
#post="%",
ticks = FALSE, animate = FALSE)
})
return(toRender)
})
}
)) |
If you change the data in a table, the table will be re-rendered, and |
@yihui it works like a charm! Thanks. |
Glad to know that :) It is not very efficient, though, to redraw the whole table every time you check/uncheck a row in the table. It may not be a real issue when the data is small. I did not test substantially larger data objects. |
@yihui I agree this method does not scale well to large amount of data. In principle one could a) cache the table each time; b) calculate the deltas for each update; c) send only the deltas after the first time (taking into account issues like partials etc.). But it is quite complex to do it right within a reactive framework. I'm still looking for someone to provide the magic... |
Dear all, |
@frajuegies Currently, yes, but I have been thinking about what to do for |
Great... |
The https://yihui.shinyapps.io/DT-checkbox/ link returns a 404 error. Any fix or is the example available at a different location? |
@jasdumas Please see http://rstudio.github.io/DT/shiny.html |
@yihui It would be great to add checkbox on datatables / DT.
I've toyed a bit with this on earlier version and I found the following issues, that would require addressing in view of a larger more general adoption:
T
& pagination isF
.The text was updated successfully, but these errors were encountered: