0

我使用 rhandsontable 包在 Shiny 应用程序中创建交互式表格。

我需要根据其他一些用户操作以编程方式选择一些单元格。但是,我在 R 的 rhandsontable 包装器中找不到这样的功能。

同时,在原生 Handsontable.js 中也绝对可以使用selectCell() 函数。我附上小的 jsfiddle 示例:

document.addEventListener("DOMContentLoaded", function() {
  var data = [
    ["", "Ford", "Volvo", "Toyota", "Honda"],
    ["2014", 10, 11, 12, 13],
    ["2015", 20, 11, 14, 13],
    ["2016", 30, 15, 12, 13]
  ];

  var container = document.getElementById('example1');
  var hot = new Handsontable(container, {
    data: data,
    minSpareRows: 1,
    rowHeaders: true,
    colHeaders: true,
    contextMenu: true
  });

  hot.selectCell(1, 0);
})
</style><!--  --><script src="https://docs.handsontable.com/0.15.0/scripts/jquery.min.js"></script><script src="https://docs.handsontable.com/0.15.0/bower_components/handsontable/dist/handsontable.full.js"></script><link type="text/css" rel="stylesheet" href="https://docs.handsontable.com/0.15.0/bower_components/handsontable/dist/handsontable.full.min.css">
<div id="example1" class="hot handsontable"></div>

http://jsfiddle.net/vz74zeqo/

所以,我可以跑步shinyjs::runjs('hot.selectCell(1,0);'),一切都会好起来的。

renderRHandsontable()但问题是:当在 Shiny 中使用函数创建时,如何学习与表关联的 JS 变量名称?(在我的例子中它被命名为hot

谢谢!

亚历克斯

4

1 回答 1

1

这篇文章有帮助: 在 Shiny 中从 textInput 搜索到 Handsontable

当我通过 then 渲染 rhandsontable 时,output$myTab = renderRHandsontable({rhandsontabe(faithful)})我可以在 JS 中使用以下命令getInstance()

HTMLWidgets.getInstance(myTab).hot.selectCell(0,1)

于 2017-09-28T04:37:56.453 回答