Skip to content

Instantly share code, notes, and snippets.

@MayaGans
Last active July 27, 2021 18:18
Show Gist options
  • Select an option

  • Save MayaGans/e3dd0393eda13729868ca8400e5367d0 to your computer and use it in GitHub Desktop.

Select an option

Save MayaGans/e3dd0393eda13729868ca8400e5367d0 to your computer and use it in GitHub Desktop.
module NS
library(shiny)
# function to make inputs
shinyInput <- function(FUN, len, id, ...) {
inputs <- character(len)
for (i in seq_len(len)) {
inputs[i] <- as.character(FUN(paste0(id, i), ...))
}
inputs
}
mod_data_ui <- function(id) {
fluidPage(
DT::dataTableOutput(NS(id, "data")),
textOutput(NS(id, 'myText'))
)
}
mod_data_server <- function(id, trainingname) {
moduleServer(id, function(input, output, session) {
datafiles <- reactiveValues(
names = c("A", "B", "C"),
number = length(c("A", "B", "C")),
file = NULL
)
df <- reactive({
data.frame(
Files = datafiles$names,
Delete = shinyInput(actionButton, datafiles$number, 'delete_btn_', label = "DELETE", class="delete_btn", onclick = paste0('Shiny.setInputValue(\"', NS(id, "select_button"), '\", this.id)'))
)
})
output$data <- DT::renderDT({
DT::datatable(
df(),
escape = FALSE,
selection = 'none',
rownames = FALSE,
options(
dom = 'lrt',
bFilter = FALSE,
bInfo = FALSE,
paging = FALSE,
lengthChange = FALSE
)
)
}, server = FALSE)
observeEvent(input$select_button, {
selectedRow <- as.numeric(strsplit(input$select_button, "_")[[1]][2])
datafiles$file <<- paste('click on ',df$data[selectedRow,1])
})
output$myText <- renderText({ datafiles$file })
})
}
# the app
ui <- fluidPage(mod_data_ui("data"))
server <- function(input, output) {
mod_data_server("data")
}
shinyApp(ui = ui, server = server)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment