In the app below Im trying to subset the lower table by clicking on a cell in the column owner
of the upper table but what I get is a subset based on the row number not on the cell value.How can I fix that?If it is fixed by selecting the whole row and not a cell then I would be open on that answer.
library(shiny)
library(shinydashboard)
library(DT)
ckall2<-structure(list(rowid = c(5704, 10243, 10116), PID = c("170040240",
"170039927", "170184811"), county = c("Cheyenne", "Cheyenne",
"Cheyenne"), ownerID = c(526, 526, NA), owner = c("RONALD WILLIAM DYKMAN",
"GREGORY VATH", "CHERYL L BORGES")), row.names = c(NA,
-3L), class = c("tbl_df", "tbl", "data.frame"))
down2<-structure(list(owner = c("GREGORY VATH","RONALD WILLIAM DYKMAN",
"CHERYL L BORGES", "JOSE & BETTY MORALES JTWRS MORALES", "CFP CAPITAL LLC"
), county = c("Cheyenne", "Cheyenne", "Cheyenne", "Cheyenne",
"Cheyenne"), acres = c(317.8073664, 5.977516111, 148.2166994,
10.01189574, 61.81147036)), sf_column = "geometry", agr = structure(c(pid = NA_integer_,
rowid = NA_integer_, county = NA_integer_, owner_d = NA_integer_,
owner = NA_integer_, address = NA_integer_, city = NA_integer_,
state = NA_integer_, zip = NA_integer_, twp_rng = NA_integer_,
trs = NA_integer_, legal = NA_integer_, acres = NA_integer_,
lst_pdt = NA_integer_, subdivs = NA_integer_, frst_nm = NA_integer_,
last_nm = NA_integer_, prprty_ = NA_integer_, sale_dt = NA_integer_,
twp = NA_integer_, rng = NA_integer_, section = NA_integer_,
landman = NA_integer_, dt_cntc = NA_integer_, dat_nkd = NA_integer_,
titlemn = NA_integer_, dt_strt = NA_integer_, date_nd = NA_integer_
), class = "factor", levels = c("constant", "aggregate", "identity"
)), row.names = c(NA, 5L), class = "data.frame")
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
dataTableOutput("TABLE"),
dataTableOutput("TABLE2"),
)
)
server <- (function(input, output, session) {
output$TABLE <- renderDataTable({
server <- TRUE
datatable(ckall2,
filter = "top", editable = "cell", class = "hover cell-border stripe",
caption = "Kimball & Cheyenne Counties AOI",
extensions = "Buttons",
options = list(
dom = "Bfrtip", scrollX = T,
buttons = c("copy", "csv", "excel")
),
selection = list(target = "cell", mode = "single"),
)
})
output$TABLE2 <- DT::renderDataTable({
req(input$TABLE_cells_selected)
owner_selected <- down2$owner[input$TABLE_cells_selected[[1]]]
down2 <- subset(down2, owner %in% owner_selected)
})
})
shinyApp(ui, server)
CodePudding user response:
Try this
output$TABLE2 <- DT::renderDataTable({
req(input$TABLE_cells_selected)
owner_selected <- ckall2$owner[input$TABLE_cells_selected[[1]]]
down2 <- subset(down2, owner %in% owner_selected)
})