When I run the code:
output$Tab<-datatable(
data.frame(
"People"=people,
"Industries"=industries,
"Schools"=schools,
"Hospitals"=hospitals),
extensions=c('Buttons','AutoFill'),options=list(dom='Bfrtip',buttons=list(
'copy','pdf','csv','excel','print'),autoFill=TRUE)
I get the following error message:
> runApp('Plots')
Listening on http://127.0.0.1:3612
Warning: Error in .subset2(x, "impl")$defineOutput: Unexpected datatables output for TabUnexpected htmlwidget output for Tab
56: stop
55: .subset2(x, "impl")$defineOutput
54: $<-.shinyoutput
52: server [C:\Users\Idiaye\Documents\Plots/app.R#178]
Error in .subset2(x, "impl")$defineOutput(name, value, label) :
Unexpected datatables output for TabUnexpected htmlwidget output for Tab
jcblum
October 17, 2018, 10:18am
2
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.
3 Likes
iFeanyi
October 17, 2018, 10:59am
3
Thanks a lot. I appreciate your help
1 Like