Issues trying to group , summarize and render table

Hello

Im trying to create a summarized table that can be rendered in a local shiny web app.

Here is a sample dataset.

df = structure(list(key = c("20210330115026950503N1CC10958295601", 
"20210330115026950503N1CC10958295602"), D_ID = c(50694622, 50694625
), D_IDDireccionamiento = c(48478384, 48478387), D_NoPrescripcion = c("20210330115026950503", 
"20210330115026950503"), D_TipoTec = c("N", "N"), D_ConTec = c(1, 
1), D_TipoIDPaciente = c("CC", "CC"), D_NoIDPaciente = c(1095829560, 
1095829560), D_NoEntrega = c(1, 2), D_NoSubEntrega = c(0, 0), 
    D_TipoIDProv = c("NI", "NI"), D_NoIDProv = c("900098550", 
    "900098550"), D_CodMunEnt = c(68001, 68001), D_FecMaxEnt = structure(c(18747, 
    18777), class = "Date"), D_CantTotAEntregar = c(2, 2), D_DirPaciente = c("0", 
    "0"), D_CodSerTecAEntregar = c("150416", "150416"), D_NoIDEPS = c(900914254, 
    900914254), D_CodEPS = c("EPS046", "EPS046"), D_FecDireccionamiento = structure(c(1617299520, 
    1617299520), tzone = "UTC", class = c("POSIXct", "POSIXt"
    )), D_EstDireccionamiento = c(2, 2), D_FecAnulacion = c(NA, 
    NA), E_ID = c(NA_real_, NA_real_), E_IDReporteEntrega = c(NA_real_, 
    NA_real_), E_NoPrescripcion = c(NA_character_, NA_character_
    ), E_TipoTec = c(NA_character_, NA_character_), E_ConTec = c(NA_real_, 
    NA_real_), E_TipoIDPaciente = c(NA_character_, NA_character_
    ), E_NoIDPaciente = c(NA_real_, NA_real_), E_NoEntrega = c(NA_real_, 
    NA_real_), E_EstadoEntrega = c(NA_real_, NA_real_), E_CausaNoEntrega = c(NA_real_, 
    NA_real_), E_ValorEntregado = c(NA_real_, NA_real_), E_CodTecEntregado = c(NA_character_, 
    NA_character_), E_CantTotEntregada = c(NA_character_, NA_character_
    ), E_NoLote = c(NA_character_, NA_character_), E_FecEntrega = structure(c(NA_real_, 
    NA_real_), class = "Date"), E_FecRepEntrega = structure(c(NA_real_, 
    NA_real_), tzone = "UTC", class = c("POSIXct", "POSIXt")), 
    E_EstRepEntrega = c(NA_real_, NA_real_), E_FecAnulacion = c(NA, 
    NA), F_ID = c(NA_real_, NA_real_), F_IDFacturacion = c(NA_real_, 
    NA_real_), F_NoPrescripcion = c(NA_character_, NA_character_
    ), F_TipoTec = c(NA_character_, NA_character_), F_ConTec = c(NA_real_, 
    NA_real_), F_TipoIDPaciente = c(NA_character_, NA_character_
    ), F_NoIDPaciente = c(NA_real_, NA_real_), F_NoEntrega = c(NA_real_, 
    NA_real_), F_NoSubEntrega = c(NA_real_, NA_real_), F_NoFactura = c(NA_character_, 
    NA_character_), F_NoIDEPS = c(NA_real_, NA_real_), F_CodEPS = c(NA_character_, 
    NA_character_), F_CodSerTecAEntregado = c(NA_character_, 
    NA_character_), F_CantUnMinDis = c(NA_real_, NA_real_), F_ValorUnitFacturado = c(NA_real_, 
    NA_real_), F_ValorTotFacturado = c(NA_real_, NA_real_), F_CuotaModer = c(NA_real_, 
    NA_real_), F_Copago = c(NA_real_, NA_real_), F_FecFacturacion = structure(c(NA_real_, 
    NA_real_), tzone = "UTC", class = c("POSIXct", "POSIXt")), 
    F_EstFacturacion = c(NA_real_, NA_real_), F_FecAnulacion = structure(c(NA_real_, 
    NA_real_), class = "Date")), row.names = c(NA, -2L), class = c("tbl_df", 
"tbl", "data.frame"))

a secondary table

precios_unitarios_mipres = structure(list(CUMS = c("00006414-02", "00011697-02", "00011699-02", 
"00016806-01", "00020677-02"), ValorUnitarioMax = c(76000, 4375, 
2767.33333333333, 564.166666666667, 318)), row.names = c(NA, 
-5L), class = c("tbl_df", "tbl", "data.frame"))

in my server code i have a routine that filters by date, select some columns, renames, does a left join against another table, filter na's out, does some additional calculations, and finally groups by D_NoIDProv and summarizes a total per D_NoIDProv . this works well in RStudio but im having trouble trying to visualize the summarized table on shiny since it just wont show at all.

I ran some checks and the table is correctly rendered before the :

group_by(D_NoIDProv ) %>% 
        summarise(sum(ValorTotal))

my server code so far

      df1 = df %>% filter(D_EstDireccionamiento!=0) %>% 
        filter(D_FecDireccionamiento >= (input$date1) & D_FecDireccionamiento <= (input$date1)) %>%
        select (D_NoIDProv, D_TipoTec, D_CodSerTecAEntregar, D_CantTotAEntregar,D_FecDireccionamiento, D_FecMaxEnt ) %>% 
        rename (CUMS = D_CodSerTecAEntregar )  %>%   
        left_join(precios_unitarios_mipres, by="CUMS") %>% 
        filter(!is.na(ValorUnitarioMax)) %>% 
        mutate (ValorTotal = round ((D_CantTotAEntregar * ValorUnitarioMax),0) ) %>% 
        mutate (ValorUnitarioMax = round (ValorUnitarioMax ,0) ) %>% 
        group_by(D_NoIDProv ) %>% 
        summarise(sum(ValorTotal))

    output$mytable = DT::renderDataTable( df1 ,
                                          filter = 'top',
                                          rownames = FALSE,
                                          options = list(autoWidth = TRUE,
                                                         columnDefs = list(list(width = '100px',className = 'dt-center' ,targets = 0:2),
                                                                           list(width = '400px',className = 'dt-center' ,targets = 3))
                                                         )
                                          )

dates are being captured from UI

airDatepickerInput(
             inputId = "date1",
             #label = "Select range of dates:",
             range = F, 
             autoClose = T,
             value = Sys.Date()+1 ,
                    #   Sys.Date()),
             todayButton = F,
             clearButton = T,
             addon = c("none")
            ),
           
           airDatepickerInput(
             inputId = "date2",
             #label = "Select range of dates:",
             range = F, 
             autoClose = T,
             value = Sys.Date()+1 ,
             #   Sys.Date()),
             todayButton = F,
             clearButton = T,
             addon = c("none")
           )

am i doing something wrong?

will appreciate your help

Try

group_by(D_NoIDProv)%>% 
        summarise(SumValorTotal=sum(ValorTotal)) %>%
ungroup()

no luck.
table doesnt populate :frowning:

I edited the initial question with better code

issue fixed. thanks to r2evans

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.