I use rhandsontable package to create interactive tables in Shiny app.
I need some cells to be selected programmatically, based on some other user actions. However, I could not find such functionality in rhandsontable wrapper in R.
Meanwhile, it is definitely possible in native Handsontable.js with selectCell()
function. I attach small jsfiddle example:
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>
So, I could run shinyjs::runjs('hot.selectCell(1,0);')
and everything would be fine.
But the question is: how can I learn the JS variable name, associated with the table, when it is created with renderRHandsontable()
function in Shiny? (in my example it is named hot
)
Thanks!
Alex
This post helped: Search from a textInput to a Handsontable in Shiny
When I rendered rhandsontable via output$myTab = renderRHandsontable({rhandsontabe(faithful)})
then I can use following command in JS getInstance()
:
HTMLWidgets.getInstance(myTab).hot.selectCell(0,1)