简体   繁体   中英

Keep current month selected in shinyWidgets::airMonthinputPicker()

I am using the airMonthpickerInput() function from the shinyWidgets package. For my particular application, the start value (month) is February 2019 (as defined in value = as.Date("2019-02-01") . This displays correctly, given the code below:

library(shiny)
library(shinydashboard)
library(shinyWidgets)

ui <- dashboardPage(
  dashboardHeader(title = "Basic dashboard"),
  dashboardSidebar(),
  dashboardBody(

             airMonthpickerInput(inputId = "select_month", label = "Select Month", value = as.Date("2019-02-01")), multiple = FALSE, autoClose = TRUE)

  )
)
)

server <- function(input, output) {


}

app<-shinyApp(ui = ui, server = server)
runApp(app, host="0.0.0.0",port=5050, launch.browser = TRUE)

However, when you try to change month, the resulting popup defaults to showing the current month (at the time of writing, January 2020). Most of the application's data is from 2019 (as you'd expect seeing as the year is now over) thus users must click the month picker, then the left arrow to show 2019's months, and then select the required month within 2019.

I would like to remove this friction (excessive button clicking) so that, when clicking the month picker, February 2019 is still highlighted (ie 2019 is displayed, not 2020). Is it possible to do this? I have checked the function's arguments but cannot see anything obvious that will allow me to show 2019 when trying to change the month.

Turns out there was a bug in shinyWidgets::airiMonthinputPicker() . A very quick bug fix from @Victorp has resolved the issue. If anyone else is currently expericing this issue, reinstall shinyWidgets from Github. Full details can be found here: https://github.com/dreamRs/shinyWidgets/issues/248

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM