以下示例应用程序以用户必须填写的空表开始。我想在他可以为 Nation 和 City 列选择的值中添加一些依赖项,因此,例如,如果他在单击 City 列时选择 Nation=Italy,则只会出现 Milan 和 Rome;反之亦然,如果他首先选择米兰,则只有意大利应该出现在自动完成列表中。建议?谢谢
library(rhandsontable)
library(shiny)
ui = fluidPage(rHandsontableOutput("data"))
server = function(input,output) {
df = data.frame(Nation = character(),City=character(),Num_Clients=integer())
values = reactiveValues(data = df)
observe({
req(input$data)
values$data = hot_to_r(input$data)
})
output$data = renderRHandsontable({
rhandsontable(values$data, height=500, minRows=1,stretchH = "all") %>%
hot_col(col="Nation",type="autocomplete",source=c("England","Spain","Mexico" ,"Italy"),strict=TRUE,allowInvalid=FALSE) %>%
hot_col(col="City",type="autocomplete",source=c("Rome","Guadalajara","Madrid ","London","Milan"),strict=TRUE,allowInvalid=FALSE) %>%
hot_validate_numeric(col = "Num_Clients", min = 0)
})
}
shinyApp(ui = ui, server = server)