0

A simple example:

library(shiny)

shinyApp(
  ui=fluidPage(
    dateInput("date","Choose a date",max=Sys.Date()),
    textOutput("text")
  ),server = function(input, output) {
    output$text=renderText(as.character(input$date))
  }
)

which has a date input. Currently, the latest date is set to the system date, but I want to change this to the client's date. How do i do that?

(I am aware of posts that talk about how to retrieve client data via javascript, but I don't know how to use those results in a dateInput object.)

Community
  • 1
  • 1
qoheleth
  • 2,219
  • 3
  • 18
  • 23

1 Answers1

2

You can use the same idea as the first answer in the link you posted and use updateDateInput in the server.R to get the client's date and change the max of your dateInput:

shinyApp(
  ui=fluidPage(
    HTML('<input type="text" id="client_time" name="client_time" style="display: none;" > '),
    tags$script('
    $(function() {
     var time_now = new Date()
     var month_now=time_now.getMonth()+1
      $("input#client_time").val(time_now.getFullYear()+"-"+month_now+"-"+time_now.getDate())
  });    
'),
    dateInput("date","Choose a date",max=Sys.Date()),
    textOutput("text")
  ),server = function(input, output,session) {
    observe({
    updateDateInput(session,"date", value = as.Date(input$client_time), max = as.Date(input$client_time))
    })
    output$text=renderText(as.character(input$date))
  }
)
Community
  • 1
  • 1
NicE
  • 21,165
  • 3
  • 51
  • 68