JavaScript库Handsontable有一个事件afterColumnResize,该事件是在手动调整列大小时触发的。如何使用它与'rhandsontable‘包在闪闪发光?
发布于 2021-01-08 21:12:27
以下是如何:
library(shiny)
library(rhandsontable)
library(htmlwidgets)
jsCode <- c(
"function(el, x) {",
" Handsontable.hooks.add('afterColumnResize', function(index, size){",
" Shiny.setInputValue('newsize', {index: index+1, size: size});",
" });",
"}"
)
ui <- fluidPage(
rHandsontableOutput("dataTable"),
br(),
verbatimTextOutput("sizeinfo")
)
server <- function(input, output, session) {
df = data.frame(
company = c('a', 'b', 'c', 'd'),
bond = c(0.2, 1, 0.3, 0),
equity = c(0.7, 0, 0.5, 1),
cash = c(0.1, 0, 0.2, 0),
stringsAsFactors = FALSE
)
output$dataTable <- renderRHandsontable({
rhandsontable(df, manualColumnResize = TRUE, manualRowResize = TRUE) %>%
onRender(jsCode)
})
output$sizeinfo <- renderPrint({
req(input$newsize)
sprintf(
"Column %d has new size %dpx.",
input$newsize$index, input$newsize$size
)
})
}
shinyApp(ui, server)

https://stackoverflow.com/questions/65636472
复制相似问题