Hi everyone,
I'm dealing with a dataset that has more than one sublevel. The structure looks like this:
I'm using a module to download data as CSV in Reactable. However, this module only downloads the first level. Below, I'm providing the module and an example application that shows the same problem. I am open to your suggestions.
library(shiny)
library(reactable)
library(dplyr)
csvDownloadButton <- function(id, filename = "data.csv", label = "Download as CSV") {
tags$button(
# Button class
class="btn btn-default action-button shiny-bound-input",
# Adding icon and label
tagList(icon("download"), label),
# Download csv
onclick = sprintf("Reactable.downloadDataCSV('%s', '%s')", id, filename),
)
}
random_requests <- data.frame(
Request_ID = c(1,2,3,4,5),
Status = c("Accepted", "Accepted", "Accepted", "Declined", "Created")
)
random_samples <- data.frame(
Request_ID = c(1,1,1,2,3,3,4,5),
Sample_ID = c(1,2,3,4,5,6,7,8),
statistics = sample(1:100, 8)
)
# Define UI for application
ui <- fluidPage(
selectInput(inputId = "select",
label = "Select a choice:",
choices = c("All", "Accepted", "Declined", "Created")),
hr(),
csvDownloadButton("table"),
reactableOutput(outputId = "table")
)
# Define server logic
server <- function(input, output) {
data <- eventReactive(input$select, {
if(input$select == "All"){
random_requests
} else {
random_requests %>%
filter(Status == input$select)
}
})
output$table <- renderReactable({
reactable(
data(),
details = function(index, name){
request_id <- data()[index, "Request_ID"]
htmltools::div(
reactable(random_samples[random_samples$Request_ID == request_id, ])
)
}
)
})
}
# Run the application
shinyApp(ui = ui, server = server)