I have a shiny dashboard app that shows a DT datatable. The raw data is manipulated in a function based on user inputs on the sidebar. All is good and working well.
My question is how do I get the data table to render in an Rmarkdown html page. Nothing I've tried works.
Here is a simple code by way of an example. I wish the table to render in an Rmarkdown page when I click a download button.
library(shiny)
library(DT)
data(iris)
ui <- fluidPage(
titlePanel("|Species Table"),
sidebarLayout(
sidebarPanel(
selectInput("specs",
"Number of bins:",
unique(iris$Species))
),
# Show a plot of the generated distribution
mainPanel(
tableOutput("specTable")
)
)
)
server <- function(input, output) {
subSpec <- function(x){
iris[iris$Species == x, -5]
iris[1:10,]
}
reactiveFunction <- reactive({ subSpec(input$specs) })
output$reactiveTable <- renderDataTable({ reactiveFunction() }, rownames = FALSE)
output$specTable <- renderUI({
dataTableOutput("reactiveTable")
})
}
shinyApp(ui = ui, server = server)