I am testing parquet files as a way to speed up a Shiny App.
The prices.csv file has been downloaded from Kaggle and converted to parquet using arrow::write_parquet and this little Shiny App has been built:
library(shiny)
library(arrow, warn.conflicts = FALSE)
library(dplyr, warn.conflicts = FALSE)
library(lubridate)
data <- read_parquet(file = "raw_data/prices.parquet")
tickers = unique(data$symbol) %>% head(250)
ui <- fluidPage(
tags$h1("Stock ticker explorer"),
selectInput(
inputId = "selectTicker",
label = "Select ticker:",
choices = tickers,
selected = tickers[1]
),
tableOutput(outputId = "pricesTable")
)
server <- function(input, output) {
output$pricesTable <- renderTable({
filtered_data <- data %>%
filter(symbol == input$selectTicker) %>%
head(15) %>%
collect()
filtered_data
})
}
shinyApp(ui, server)
In the Shiny App code, I do not understand that
data <- read_parquet(file = "raw_data/prices.parquet")
returns
# A tibble: 851,264 × 7
date symbol open close low high volume
<dttm> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
1 2016-01-05 00:00:00 WLTW 123. 126. 122. 126. 2163600
2 2016-01-06 00:00:00 WLTW 125. 120. 120. 126. 2386400
3 2016-01-07 00:00:00 WLTW 116. 115. 115. 120. 2489500
4 2016-01-08 00:00:00 WLTW 115. 117. 114. 117. 2006300
5 2016-01-11 00:00:00 WLTW 117. 115. 114. 117. 1408600
6 2016-01-12 00:00:00 WLTW 116. 116. 114. 116. 1098000
7 2016-01-13 00:00:00 WLTW 116. 113. 113. 117. 949600
8 2016-01-14 00:00:00 WLTW 114. 114. 110. 115. 785300
9 2016-01-15 00:00:00 WLTW 113. 113. 112. 115. 1093700
10 2016-01-19 00:00:00 WLTW 114. 110. 110. 116. 1523500
# … with 851,254 more rows
when executed in R, but when I run the App, I get the date in UNIX format:
- Why is the output not respecting the format of the data object in R?
- How can I convert this Unix date to a normal date format?
I have uncessfully tried:
server <- function(input, output) {
output$pricesTable <- renderTable({
filtered_data <- data %>%
filter(symbol == input$selectTicker) %>%
head(15) %>%
mutate(date = as.POSIXct(date)) %>%
collect()
filtered_data
})
}