My project involves using the rhandsontable package to generate dynamic tables within a Shiny app.
I am in need of a solution that allows me to select certain cells programmatically, triggered by specific user interactions. Unfortunately, I have not been able to locate such functionality within the R-based rhandsontable wrapper.
In contrast, I have discovered that this selection capability is achievable with native Handsontable.js through the use of the selectCell()
function. An illustrative example can be found below:
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, by executing
shinyjs::runjs('hot.selectCell(1,0);')
, the desired outcome can be achieved seamlessly.
The key question now arises: how can one determine the variable name associated with the table when it is generated using the renderRHandsontable()
function in Shiny? (as illustrated by the variable name hot
in my case)
Your input would be greatly appreciated!
Regards,