如何访问在 Shiny 中渲染的 rhandsontable 的 JS 变量名?

How can I access JS variable name for rhandsontable rendered in Shiny?

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

我需要根据其他一些用户操作以编程方式选择一些单元格。 但是,我在 R.

的 rhandsontable wrapper 中找不到这样的功能

同时,在原生 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);') 一切都会好起来的。

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

谢谢!

亚历克斯

这 post 帮助: Search from a textInput to a Handsontable in Shiny

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

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