I have a rhandsontable with two columns named Method and Capitalization Order. I have tried to attach a dropdown list to the cell of the Capitalization Order conditioned by the value of the Method. However, I am getting the "Error: trying to select less than one element in get1index".
What is wrong with my script below? I would be grateful for any help.
df1 <- data.table(
"Method" = as.character("Uniform", "Uniform"),
"Capitalization Order" = NA_character_,
stringsAsFactors = FALSE
)
ui <- dashboardPage(
dashboardHeader(title = "FV CALCULATION"),
dashboardSidebar(
menuItem("Home", tabName = "home")
),
dashboardBody(
tabItems(
tabItem(
tabName = "home",
column(
"Fair Value Calculation",
width = 12,
rHandsontableOutput("TableV1"),
)
)
)
)
)
server <- function(input, output) {
DF1 <- reactiveVal(data.frame(df1))
observeEvent(input$TableV1, {
DF1(hot_to_r(input$TableV1))
})
output$TableV1 <- renderRHandsontable({
CapitalizationOrderOptions <- c(NA_character_, "monthly", "quarterly", "semi-annual", "annual")
DF2 <- rhandsontable(DF1(), rowHeaders = NULL, stretchH = "all", selectCallback = TRUE, height = 300) %>%
hot_col("Method", readOnly = TRUE) %>%
hot_col("Capitalization Order", allowInvalid = FALSE, type = "dropdown", source = NA_character_, readOnly = TRUE)
if (!is.null(input$TableV1_select$select$r)) {
selectedMethod <- DF1()[input$TableV1_select$select$r, "Method"]
if (selectedMethod == "Uniform") {
DF2 <- DF2 |>
hot_col(col = "Capitalization Order", allowInvalid = FALSE, type = "dropdown", source = CapitalizationOrderOptions) |>
hot_cell(row = input$TableV1_select$select$r, col = "Capitalization Order", readOnly = FALSE) |>
hot_table(contextMenu = FALSE)
}
}
DF2
})
}
shinyApp(ui = ui, server = server)