You need to wrap your call to DT::datatable
in a renderDataTable()
statement. Here's an example:
library(shiny)
library(DT)
shinyApp(
ui = fluidPage(
dataTableOutput("Tab")
),
server = function(input, output, session) {
output$Tab <- datatable(
mtcars
)
}
)
Running the above gives me the same error as you saw:
Listening on http://127.0.0.1:3334
Warning: Error in .subset2(x, "impl")$defineOutput: Unexpected datatables output for TabUnexpected htmlwidget output for Tab
51: stop
50: .subset2(x, "impl")$defineOutput
49: $<-.shinyoutput
47: server [/cloud/project/unexpected_datatables.R#10]
Error in .subset2(x, "impl")$defineOutput(name, value, label) :
Unexpected datatables output for TabUnexpected htmlwidget output for Tab
But if I do this, the app works as expected:
library(shiny)
library(DT)
shinyApp(
ui = fluidPage(
dataTableOutput("Tab")
),
server = function(input, output, session) {
output$Tab <- renderDataTable(
datatable(mtcars)
)
}
)
If you haven't already, it's worth taking the time to go through the shiny tutorials — they really help with understanding how all the pieces fit together with shiny code.