Dataframe not loading on RenderDataTable

I'm running some code where I'm trying to render a dataframe in a Shiny App. When I test the code locally without using a dynamic input filter the table is created ok, but when I run it in Shiny I get the following error. I don't see how this wouldn't be a dataframe.

Warning: Error in datatable: 'data' must be 2-dimensional (e.g. data frame or matrix)
[No stack trace available]

A summary of the code is

server <- function(input, output) {
  # Outputs for totals
  output$Total_tableAll <- DT::renderDataTable({

...

    Total_table<-Total_PremLoss %>% 
      group_by(CY)%>%
      dplyr::summarise('Booked Premium'=sum(Booked_Prem),
                       'Earned Premium' = sum(EP),
                       Commission=sum(Commission)/sum(EP),
                       Incurred=sum(Incurred),
                       ILR = sum(Incurred)/sum(EP),
                       'NonCAT ILR' = sum(nonCATLoss)/sum(EP),
                       'CAT ILR' = sum(CATLoss)/sum(EP),
                       'Comm ILR'= Commission+ILR)

    DT::datatable(data = Total_table,
                 container=cont_total,
                 rownames = FALSE,
                 caption = 'All LOB',
                 option=list(dom='t'
                 ))%>%
     formatCurrency(
       c('Booked Premium', 'Earned Premium', 'Incurred'),
       currency="$",digits=0)%>%
     formatPercentage(
       c('ILR', 'NonCAT ILR', 'CAT ILR', 'Comm ILR', 'Commission'))
)}

Hi, welcome!

To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue including sample data on a copy/paste friendly format? Please have a look at this guide, to see how to create one for a shiny app

Just for reference I wanted to mention that I solved this. I didn't realize DT::renderDataTable({ required to have the table you are trying to render at the end of the wrapped statement. I moved this to the end and now it works ok.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.