问题描述
我正在使用 RHandsontable 开发 R Shiny 应用程序。在表格中,应该可以通过单击和拖放来移动行。所以我设置了 manualRowMove = TRUE
并且它有效。
我现在的问题是,如何获取当前显示的表格(行移动后)?
我的 JavaScript 能力很差(这就是主要问题),但我想我需要“afterRowMove”钩子。当用户移动一行时,如何获得反应信息?或者,它不必是响应式的,因为我添加了一个自己的上下文菜单项,如果触发了该项,那么我需要知道表的哪一行在哪里(索引不起作用!)。
请帮帮我。我读了很多关于 hooks 和 Handsontable 的内容,但所有内容都在 JS 中,我无法将其转移到 R 中。
切夫科赫
这是一个小例子:
library(shiny)
library(rhandsontable)
library(shiny)
library(rhandsontable)
library(dplyr)
library(stringr)
library(data.table)
options(scipen = 99999)
options(encoding = "UTF-8")
ui <- fluidRow(
rHandsontableOutput("foo"),fluidRow(
verbatimtextoutput("sel")
)
)
server <- function(input,output) {
table <- cbind(nr = 1:10,iris[1:10,])
output$foo = renderRHandsontable({
rhandsontable(
table,manualRowMove = TRUE,rowHeaders = TRUE
) %>%
hot_context_menu(allowColEdit = FALSE,alignment = FALSE,customOpts = list(
reload = list(
name = "own_item",callback = htmlwidgets::JS(
"function () {
val = this.getSelectedLast();
Shiny.setInputValue('own_item',{row1: val[0] + 1,row2: val[2] + 1},{priority: 'event'})
}"
)
)
)
)
})
output$sel = renderPrint({
print("Doing something with the index of the marked Rows (which is wrong after movings): ")
print(paste0("stored index: ",input$own_item$row1,",possible wrong entry: ",paste0(table[input$own_item$row1,],collapse = ",")))
})
}
# Run the application
shinyApp(ui = ui,server = server)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)