I'm trying to collect the value of a column ('Type') in a rhandsontable based on the the selection of the adjacent logical column ('Tick'). I want to create a vector of all the Type's based on the which rows are ticked.
I will use the vector to subset the columns in the other rhandsontable 'Aims'
I'm getting the error
Warning: Error in match: 'match' requires vector arguments
library(rhandsontable)
library(shiny)
orgs <- c("Community leaders/representatives",
"Members of local community/indigenous committees",
"Landowners/customary area owners",
"National government",
"Sub-national or local government",
"Managed area manager/personnel",
"International NGO",
"Local or national NGO",
"Community based organizations - women’s groups",
"Community based organizations - men’s groups",
"Community based organizations - youth/school groups",
"Community based organizations - religious groups",
"Community based organizations - conservation groups",
"Industry",
"Private sector",
"Academic institute or research facility",
"Other")
proj_aim3 <- data.frame(Category = c("Area", "Condition", "Diversity"))
proj_aim3 <- cbind(proj_aim3, setNames( lapply(orgs, function(x) x=NA), orgs) )
ui <- fluidPage(
rHandsontableOutput('Intiated'),
verbatimTextOutput('selected'),
br(),
rHandsontableOutput("Aims2")
)
server <- function(input, output, session) {
cats <- c("Community leaders/representatives", "Members of local community/indigenous committees", "Landowners/customary area owners", "National government", "Sub-national or local government", "Managed area manager/personnel",
"International NGO", "Local or national NGO", "Community based organizations - women’s groups", "Community based organizations - men’s groups",
"Community based organizations - youth/school groups", "Community based organizations - religious groups", "Industry", "Private sector",
"Academic institute or research facility", "Not recorded", "Other")
DF <- data.frame(Tick = rep(FALSE, length(cats)), Type = cats, Name = rep("", length(cats)))
output$Intiated <- renderRHandsontable(
rhandsontable(DF, selectCallback = TRUE, readOnly = FALSE)
)
selected2 <- reactive({
dat <- hot_to_r(input$Intiated)
if (any(dat[[1]])) {
dat[which(dat[[1]]), 2]
}
})
output$selected <- renderPrint({
cat(paste(selected2(), collapse = "\n"))
})
Aims_DF_NEW <- proj_aim3
imps2 <- c("Primary", "Secondary", "Tertiary")
sel <- selected2
output$Aims2 <- renderRHandsontable({
Aims_DF_NEW <- Aims_DF_NEW[, which(names(Aims_DF_NEW) %in% sel)]
rhandsontable(Aims_DF_NEW, rowHeaders = NULL, width = 1500, height = 600) %>%
hot_col(col = "Category", readOnly = T) %>%
hot_cols(cols = Aims_DF_NEW[,2:ncol(Aims_DF_NEW)], type = "autocomplete", source = imps2, strict = TRUE, colWidths = 200)})
}
shinyApp(ui = ui, server = server)