【问题标题】:How can I access JS variable name for rhandsontable rendered in Shiny?如何访问在 Shiny 中呈现的 rhandsontable 的 JS 变量名?
【发布时间】:2018-03-09 00:00:14
【问题描述】:

我使用 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);'),一切都会好起来的。

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

谢谢!

亚历克斯

【问题讨论】:

    标签: javascript r shiny handsontable rhandsontable


    【解决方案1】:

    这篇文章有帮助: Search from a textInput to a Handsontable in Shiny

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

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

    【讨论】:

      猜你喜欢
      • 2022-11-22
      • 2021-04-14
      • 1970-01-01
      • 2020-10-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-12
      • 2022-01-02
      相关资源
      最近更新 更多