1
votes

I want to use dateInput in a way that on refresh of shiny web page the app gets the actual value attribute from Sys.Date()-1. Presently, if I launch the app on 2016-09-20 and come to visit it again on 25th the value of dateInput is still 20th.

Is this not reactive by default? Should I render the yesterdays date as character in server as text input or similar?

The ui context:

dateInput(inputId="datex", label="Select Date", value=Sys.Date()-1,
                                                      format = "yyyy-mm-dd",
                                                      startview = "month" )

As the documentation for shiny´s dateInput makes use of Sys.Date minus a number of days I think it should be reactive context and pretty much straight forward:

 # from docu: Pass in a Date object
   dateInput("date4", "Date:", value = Sys.Date()-10)

Your suggestion is appreciated!

1

1 Answers

2
votes

You should put the dateInput as a uiOutput so everytime a session starts dateInput will be rendered.

rm(list = ls())
library(shiny)
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(),
  dashboardBody(
    uiOutput("myui")    
  )
)
server <- function(input, output) {
  output$myui <- renderUI({
    dateInput(inputId="datex", label="Select Date", value=Sys.Date()-1,
              format = "yyyy-mm-dd",
              startview = "month" )
  }) 
}
shinyApp(ui, server)