我正在尝试构建一个Shiny应用程序,并获取onClick
函数来输出用户单击的单元格行/列。
如何修复代码以显示单元格行/列?
闪亮应用
library(reactable)
library(shiny)
library(htmlwidgets)
iris = iris
ui <- fluidPage(
reactable::reactableOutput("irisTABLE"),
textOutput("'cellDATA")
)
# Define server logic required to draw a histogram
server <- function(input, output) {
output$irisTABLE = renderReactable({
reactable(iris,
onClick = JS("
function(rowInfo, colInfo) {
Shiny.setInputValue('cell_data', colInfo.id + '-' + rowInfo.row.CapRate, { priority: 'event' })
}
")
)
})
output$cellDATA = renderText({
paste0("The cell selected is: ", input$cell_data)
})
}
# Run the application
shinyApp(ui = ui, server = server)
1条答案
按热度按时间vuktfyat1#
将
output$cellDATA
更改为if (!is.null(input$cell_data)) { row_col <- strsplit(input$cell_data, "-") paste0("The cell selected is in row ", row_col[[1]][2], " and column ", row_col[[1]][1]) }