1
votes

I display the birthdate of people in a shiny app using dateInput(). When nobody is selected, the value of this input field needs to be set to empty, or NULL. I tried value = "",
value = " " value = NULL

but none of them works. The content of the field sets itself to the current date.

How to display empty Date fields using dateInput()?

I also would like to sometimes disable the dateInput widget using shinyjs::disable(), but this function seem to be unable to disable the dateInput widget. Is that normal?

2

2 Answers

1
votes

You could use renderUI() and wrote a dynamic control. See here: http://shiny.rstudio.com/articles/dynamic-ui.html

ui.R

# Partial example
numericInput("ind", "individual"),
uiOutput("datecontrol")
server.R

Partial example

output$datecontrol<- renderUI({
if(!is.null(input$ind) )  date <- dateInput()
})
0
votes

In regards to your second question, shinyjs::disable() should work on dateInput(). I just tried it and it works for me

library(shiny)
library(shinyjs)

shinyApp(
  ui = fluidPage(
    useShinyjs(),
    dateInput("date", "Date"),
    actionButton("btn", "Disable")
  ),
  server = function(input, output, session) {
    observeEvent(input$btn, disable("date"))
  }
)