Created
May 1, 2016 23:36
-
-
Save fbreitwieser/5934feadfbdff03eb400cd2187b6b80b to your computer and use it in GitHub Desktop.
Buttons in DT (ziyasaeed in https://github.com/rstudio/DT/issues/178)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
library(DT) | |
shinyApp( | |
ui <- fluidPage( | |
DT::dataTableOutput("data") | |
), | |
server <- function(input, output) { | |
shinyInput <- function(FUN, len, id, ...) { | |
inputs <- character(len) | |
for (i in seq_len(len)) { | |
inputs[i] <- as.character(FUN(paste0(id, i), ...)) | |
} | |
inputs | |
} | |
df <- reactiveValues(data = data.frame( | |
Delete = shinyInput(actionButton, 10, 'button_', label = "Delete", onclick = 'Shiny.onInputChange(\"select_button\", this.id)' ), | |
Value1 = 1:10, | |
Value2 = c("A", "B", "C", "D", "E"), | |
stringsAsFactors = FALSE, | |
row.names = 1:10 | |
)) | |
output$data <- DT::renderDataTable( | |
df$data, server = FALSE, escape = FALSE, selection = 'none' | |
) | |
observeEvent(input$select_button, { | |
selectedRow <- as.numeric(strsplit(input$select_button, "_")[[1]][2]) | |
df$data <- df$data[rownames(df$data) != selectedRow, ] | |
}) | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment