I made an app that is triggered when I use a database by fileInput. The database is this df
that I inserted below, but it is in excel format. This base that is in excel I insert in fileInput.
df <- structure(
list(date = c("2021-01-01","2021-01-02","2021-01-03","2021-01-04","2021-01-05"),
d1 = c(0,1,4,5,6), d2 = c(2,4,5,6,7)),class = "data.frame", row.names = c(NA, -5L))
}
However, would I like to change the selectInput()
that refers dates to a dateInput()
? Also, I would like the dates to be presented in day-month-year style.
library(shiny)
library(shinythemes)
library(openxlsx)
library(shinyBS)
library(shinyWidgets)
library(openxlsx)
library(writexl)
library(readxl)
ui <- fluidPage(
ui <- shiny::navbarPage(theme = shinytheme("flatly"), collapsible = TRUE,
br(),
tabPanel("",
fileInput("file", "Please upload a file", accept = c(".xlsx")),
sidebarLayout(
sidebarPanel(
selectInput("date", label = h4("Date"),""),
selectInput("d1", label = h4("D1"),""),
selectInput("d2", label = h4("D2"),""),
br(),
),
mainPanel(
))
)))
server <- function(input, output, session) {
df1 <- reactiveValues(dat=NULL)
data <- eventReactive(input$file, {
if (is.null(input$file)) return(NULL)
df <- read_excel(input$file$datapath)
df
})
observe({
df1$dat <- data()
})
observeEvent(input$file, {
if (!is.null(df1$dat)) {
data <- df1$dat
updateSelectInput(session, "date", label = "Date", unique(data$Date))
updateSelectInput(session, "d1", label = "D1", unique(data$D1))
updateSelectInput(session, "d2", label = "D2", unique(data$D2))
}
})
}
shinyApp(ui = ui, server = server)