Home > Blockchain >  Leave no selected date on shiny calendar
Leave no selected date on shiny calendar

Time:10-18

I made a code in Shiny just as an example. As you can see, I have a calendar. I wish that instead of the calendar field being empty, I would like it had something like this written: No date selected

Is there any way to do this?

library(shiny)
library(shinythemes)


ui <- fluidPage(
  
  shiny::navbarPage(theme = shinytheme("flatly"), collapsible = TRUE,
                    br(),
                    tabPanel("",
                             sidebarLayout(
                               sidebarPanel(
                                 uiOutput("date"),

                                 br()
                                 
                               ),
                               mainPanel(
                                   ),
                             ))
  ))

server <- function(input, output,session) {
  

  output$date <- renderUI({
    req(data())
    all_dates <- seq(as.Date('2021-01-01'), as.Date('2021-01-15'), by = "day")
    disabled <- as.Date(setdiff(all_dates, as.Date(data()$df)), origin = "1970-01-01")
    dateInput(input = "database", 
              label = h4("Choose"),
              min = min(data()$df),
              max = max(data()$df),
              value = NA,
              datesdisabled = disabled)
    
  })

}

shinyApp(ui = ui, server = server) 

CodePudding user response:

I would add a "placeholder" HTML attribute to the input element. This could be tidier, but this is the general idea... replace your dateInput with:

myDateInput <- dateInput(input = "database", 
                         label = h4("Choose"),
                         min = min(data()$df),
                         max = max(data()$df),
                         value = NA,
                         datesdisabled = disabled)

myDateInput$children[[2]]$attribs$placeholder <- "No date selected"
myDateInput

Quick side note, your code is throwing a lot of warnings; min, max and datesdisabled aren't being used correctly.

  • Related