1

我在我的应用程序中使用 Rhandsontable,我想在我的 Date 列中使用月-年级别的 datepicker。我写了一个代码,但它不工作。请参考下面的代码,如果您能找到任何问题,请告诉我。

library(shiny)
library(rhandsontable)

shinyApp(
  ui = fluidPage(
    tags$head(tags$script(src="pikaday.js")),
    tags$head(tags$style(HTML('
                            /* main sidebar */
                            .htDatepickerHolder .pika-table {
                            display: none !important;
                            }'
    ))),
                   tags$head(tags$script(HTML('var picker= new Pikaday(
                                              {
                                              field: document.getElementById("datePicker"),
                                              firstDay: 1,
                                              minDate: new Date(2000, 0, 1),
                                              maxDate: new Date(2020, 12, 31),
                                              yearRange: [2000, 2020],
                                              bound: true,
                                              onDraw: function() { console.log(this.calendars[0].month, this.calendars[0].year); }
                                              });'
      )
                   )
                   ),
    fluidRow(
      column(12
             ,
             rHandsontableOutput('table')
      )
    )
  ),
  server = function(input, output) {
    DF = data.frame(val = 1:10, bool = TRUE, big = LETTERS[1:10],
                    small = letters[1:10],
                    dt = seq(from = Sys.Date(), by = "days", length.out = 10),
                    stringsAsFactors = FALSE)

    # try updating big to a value not in the dropdown
    output$table <- renderRHandsontable(
      rhandsontable(DF, rowHeaders = NULL, width = 550, height = 300) %>%
        hot_col(col = "big", type = "dropdown", source = LETTERS) %>%
        hot_col(col = "small", type = "autocomplete", source = letters,
                strict = FALSE)
    )
  }
)

上述代码中使用的 Pikaday.js 可以参考这里:- https://github.com/dbushell/Pikaday/blob/master/pikaday.js

4

0 回答 0