Я взял на себя проект, который использует некоторую аккуратную функцию для удаления пустых / уродливых столбцов перед рендерингом с DT::renderDT()
.Значение ячейки в данном столбце может представлять другую таблицу, и я хотел бы сослаться на них.Поэтому, если пользователь щелкает ячейку, приложение должно отобразить другую таблицу с таким именем.Однако значения ячеек только однозначно связаны с другими таблицами в контексте имен столбцов. input$tbl_cell_clicked
предоставляет только индексы, а не имена столбцов.Функция очистки может удалить пустые столбцы, поэтому я не могу полагаться на номера индексов.
Как получить текущие отображаемые имена столбцов таблицы?
library(shiny)
library(DT)
shinyApp(
ui = fluidPage(fluidRow(column(12, DTOutput('tbl')))),
server = function(input, output) {
output$tbl = renderDT(
#I took over a project that uses some tidy functions to drop empty/ugly columns before rendering
#column names and order therefore cannot be guranteed, here exemplified with use of sample()
iris[,sample(ncol(iris),3)], options = list(lengthChange = FALSE)
)
#i need to know the cell value and column name of latest click gesture, not only index col
observe({
#how can I retrieve the column name that cell clicked was in?
print(input$tbl_cell_clicked)
#The rendered table iris[,sample(ncol(iris))] cannot be scoped from here
#Don't wanna go down that road of <<- solutions
#could be solved by dumping latest iris[,sample(ncol(iris),3)] into a reactive values,
#but that might look messy to use extra lines to save metadata from latest rendered DT
})
}
)