首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用“afterColumnResize”事件和“rhandsontable”?

如何使用“afterColumnResize”事件和“rhandsontable”?
EN

Stack Overflow用户
提问于 2021-01-08 21:11:16
回答 1查看 152关注 0票数 1

JavaScript库Handsontable有一个事件afterColumnResize,该事件是在手动调整列大小时触发的。如何使用它与'rhandsontable‘包在闪闪发光?

EN

回答 1

Stack Overflow用户

发布于 2021-01-08 21:12:27

以下是如何:

代码语言:javascript
复制
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)

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65636472

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档