library(shiny)
library(DT)
data(iris)
ui <- fluidPage(
titlePanel("|Species Table"),
sidebarLayout(
sidebarPanel(
selectInput("specs",
"Number of bins:",
unique(iris$Species)),
downloadButton("download", "Download Report")
),
mainPanel(
tableOutput("specTable")
)
)
)
server <- function(input, output) {
subSpec <- function(x){
testdat <- iris[iris$Species == x, ]
return(testdat[1:10,])
}
reactiveFunction <- reactive({ subSpec(input$specs) })
output$reactiveTable <- renderDataTable({ reactiveFunction() }, rownames = FALSE)
output$specTable <- renderUI({
dataTableOutput("reactiveTable")
})
output$download <- downloadHandler(
filename <- "report_file.html",
content <- function(file){
write.csv(reactiveFunction(), "test_csv.csv", row.names = FALSE)
params <- list(data = reactiveFunction())
rmarkdown::render(filename, output_file = file)
}
)
}
shinyApp(ui = ui, server = server)