How to output the default date in dateInput()?

Viewed 191

I want to do the same thing but with dateInput(). How would I go about outputting the default date set in the dateInput() to say a verbatimTextOutput()?

Code:

library(shiny)
library(shinythemes)

ui <- fluidPage(      
  theme = shinytheme('slate'),

  sidebarPanel(
    selectInput(
      'country',
      'Select a Country',
      c('Japan', 'China', 'USA'),
      selected = 'Japan'
    ),

    dateInput(
      'date',
      label = 'Select a Date',
      value = as.character(as.Date('05/10/20', '%m/%d/%y')),
      min = as.Date('01/22/20', '%m/%d/%y'),
      max = as.Date('05/10/20', '%m/%d/%y'),
      format = 'mm/dd/yy',
      startview = 'month',
      weekstart = 1
    ),

    actionButton('resetBtn', 'Reset'),

    actionButton('plotBtn', 'Plot', class = 'btn-primary')
  ),
  mainPanel(
    verbatimTextOutput('dateText', placeholder = TRUE)
  )
)

server <- function(input, output) {

  dateInput <- eventReactive(input$plotBtn, {
    input$date
  }, ignoreNULL = FALSE)

  output$dateText <- renderText({
    as.character(dateInput())
  })
}


shinyApp(ui, server)

The above code still doesn't work and I can't find an answer online that matches this.

1 Answers

Use renderPrint instead of renderText.

Related