Dates in a Shiny app renderTable from tidyverse::subset presenting as numbers in the app.

Hi, in the UI of my shiny app is a table which is produced by a piped tidyverse::subset in the server. When the same code is run in notebook it produces a desirable table with dates in standard r format e.g. 2020-10-1. However, In shiny, dates look like this e.g. 17176.00 . How do I make the date present in readable format in my shiny app? (while retaining the standard format of the date where it is required to subset the table).

I have provided a small version of the code:

library(shiny)
library(tidyverse)

access_min <- structure(list(rid = c(2331, 2332, 2333, 2334, 2335, 2336, 2337, 
                       2338, 2339, 2340, 2341, 2342, 2343, 2344, 2346, 2347, 2348, 2349, 
                       2350, 2351, 2352, 2353, 2354, 2355, 2356, 2357, 2358, 2359, 2360, 
                       2361, 2362, 2363, 2364, 2365, 2367, 2368, 2369, 2370, 2371, 2372, 
                       2373, 2374, 2375, 2376, 2377, 2378, 2379, 2380, 2383, 2384, 2385, 
                       2386, 2387, 2388, 2389, 2390, 2391, 2392, 97, 97), received = c("04/12/2020", 
                                                                                       "04/12/2020", "04/12/2020", "07/12/2020", "07/12/2020", "07/12/2020", 
                                                                                       "07/12/2020", "07/12/2020", "07/12/2020", "07/12/2020", "07/12/2020", 
                                                                                       "07/12/2020", "07/12/2020", "07/12/2020", "08/12/2020", "09/12/2020", 
                                                                                       "09/12/2020", "27/11/2020", "09/12/2020", "09/12/2020", "10/12/2020", 
                                                                                       "10/12/2020", "10/12/2020", "11/12/2020", "10/12/2020", "11/12/2020", 
                                                                                       "10/12/2020", "11/12/2020", "11/12/2020", "13/12/2020", "14/12/2020", 
                                                                                       "14/12/2020", "15/12/2020", "16/12/2020", "16/12/2020", "16/12/2020", 
                                                                                       "16/12/2020", "17/12/2020", "17/12/2020", "17/12/2020", "17/12/2020", 
                                                                                       "17/12/2020", "17/12/2020", "18/12/2020", "21/12/2020", "22/12/2020", 
                                                                                       "22/12/2020", "22/12/2020", "22/12/2020", "22/12/2020", "23/12/2020", 
                                                                                       "24/12/2020", "24/12/2020", "24/12/2020", "29/12/2020", "29/12/2020", 
                                                                                       "29/12/2020", "30/12/2020", "10/01/2017", "10/01/2017"), decided = c("10/12/2020", 
                                                                                                                                                            "04/12/2020", "08/12/2020", "07/12/2020", "07/12/2020", "07/12/2020", 
                                                                                                                                                            "-", "07/12/2020", "22/12/2020", "07/12/2020", "07/12/2020", 
                                                                                                                                                            "07/12/2020", "-", "07/12/2020", "09/12/2020", "09/12/2020", 
                                                                                                                                                            "-", "09/12/2020", "09/12/2020", "10/12/2020", "14/12/2020", 
                                                                                                                                                            "15/12/2020", "11/12/2020", "11/12/2020", "23/12/2020", "16/12/2020", 
                                                                                                                                                            "-", "-", "11/12/2020", "-", "15/12/2020", "15/12/2020", "15/12/2020", 
                                                                                                                                                            "17/12/2020", "-", "-", "17/12/2020", "-", "-", "-", "-", "22/12/2020", 
                                                                                                                                                            "-", "18/12/2020", "24/12/2020", "-", "22/12/2020", "-", "22/12/2020", 
                                                                                                                                                            "22/12/2020", "23/12/2020", "24/12/2020", "24/12/2020", "-", 
                                                                                                                                                            "-", "-", "-", "30/12/2020", "09/10/2017", "09/10/2017"), start = c("-", 
                                                                                                                                                                                                                                "04/12/2020", "-", "07/12/2020", "07/12/2020", "07/12/2020", 
                                                                                                                                                                                                                                "-", "07/12/2020", "22/12/2020", "07/12/2020", "07/12/2020", 
                                                                                                                                                                                                                                "07/12/2020", "-", "07/12/2020", "08/12/2020", "09/12/2020", 
                                                                                                                                                                                                                                "-", "10/12/2020", "09/12/2020", "10/12/2020", "10/12/2020", 
                                                                                                                                                                                                                                "-", "11/12/2020", "11/12/2020", "-", "-", "-", "-", "11/12/2020", 
                                                                                                                                                                                                                                "-", "15/12/2020", "14/12/2020", "15/12/2020", "-", "-", "-", 
                                                                                                                                                                                                                                "17/12/2020", "-", "-", "-", "-", "-", "-", "18/12/2020", "24/12/2020", 
                                                                                                                                                                                                                                "-", "22/12/2020", "-", "23/12/2020", "23/12/2020", "23/12/2020", 
                                                                                                                                                                                                                                "-", "24/12/2020", "-", "-", "-", "-", "30/12/2020", "16/01/2017", 
                                                                                                                                                                                                                                "16/01/2017"), exited = c("-", "-", "-", "-", "17/12/2020", "-", 
                                                                                                                                                                                                                                                          "-", "08/12/2020", "-", "-", "10/12/2020", "-", "-", "08/12/2020", 
                                                                                                                                                                                                                                                          "09/12/2020", "18/12/2020", "-", "-", "-", "-", "-", "-", "14/12/2020", 
                                                                                                                                                                                                                                                          "23/12/2020", "-", "-", "-", "-", "20/12/2020", "-", "-", "-", 
                                                                                                                                                                                                                                                          "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "05/01/2021", 
                                                                                                                                                                                                                                                          "-", "23/12/2020", "-", "-", "-", "30/12/2020", "-", "-", "-", 
                                                                                                                                                                                                                                                          "-", "-", "-", "-", "-", "-"), rejected = c("10/12/2020", "-", 
                                                                                                                                                                                                                                                                                                      "08/12/2020", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", 
                                                                                                                                                                                                                                                                                                      "-", "-", "-", "-", "-", "-", "-", "-", "15/12/2020", "-", "-", 
                                                                                                                                                                                                                                                                                                      "23/12/2020", "16/12/2020", "-", "-", "-", "-", "-", "-", "-", 
                                                                                                                                                                                                                                                                                                      "-", "-", "-", "-", "-", "-", "-", "-", "22/12/2020", "-", "-", 
                                                                                                                                                                                                                                                                                                      "-", "-", "-", "-", "-", "-", "-", "24/12/2020", "-", "-", "-", 
                                                                                                                                                                                                                                                                                                     "-", "-", "-", "-", "-")), row.names = c(NA, -60L), class = c("tbl_df","tbl", "data.frame"))

access_min$received <- dmy(access_min$received)
access_min$decided <-  dmy(access_min$decided)
access_min$start <-    dmy(access_min$start)
access_min$exited <-   dmy(access_min$exited)
access_min$rejected <- dmy(access_min$rejected)

options(shiny.autoreload = TRUE)

ui <- fluidPage(
    titlePanel("MinRep"),
    
    sidebarLayout(
        sidebarPanel(
            helpText("MinRep"),
            
    
            #view table
            actionButton(
                "table",
                label = "View table"
            )
        ),
        
        mainPanel(
            tableOutput("table")
            )
        )
)

server <- function(input, output, session) {
    
    structure_table <- 
        reactive({
            access_min %>%
                subset(access_min$received >= '2020-12-15')
        })
    
    
    plot_table <- eventReactive(input$table, {
        structure_table()
    })
    output$table <- renderTable({
        plot_table()
    }, 
    striped = TRUE,
    bordered = TRUE,
    rownames = TRUE,
    na = ""
    )
}

shinyApp(ui = ui, server = server)

please read the reprex guide, you can use dput on the output of your read_excel function call and share that in the form of code text in the forum.
FAQ: How to do a minimal reproducible example ( reprex ) for beginners

Apologies, have updated to full minrep.

Is it possibly to give me any guidance on the example as it stands now that I've updated it?

Have you run what you shared ?
because it looks fine to my eyes...
ahhh, it looked fine, because you didnt load the lubridate library, so the data wasnt transformed from character to date

The solution for you is to apply a printing format for your dates for example:

 
  structure_table <- 
    reactive({
      access_min %>%
        subset(access_min$received >= '2020-12-15') %>%
        mutate_if(is.Date,~format(.,"%d-%m-%Y"))
    })

fantastic thanks, sorry for forgetting to load lubridate

1 Like

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.