【发布时间】:2023-02-08 02:43:09
【问题描述】:
我需要将焦点放在 RShiny 应用程序中 rhandsontable 的第一行第一列单元格上。寻找与本论坛中讨论的解决方案类似的解决方案:Set the focus to a specific datagrid cell、QML: Set focus TextInput in a table cell、how to focus a table cell using javascript?、want to put the focus and edit the first cell of my dynamic table 等。我需要渲染器功能方面的帮助才能完成此任务。
library(shiny)
library(rhandsontable)
DF = data.frame(matrix(data = '', nrow = 5, ncol = 1, dimnames = list(seq(1:5),c("Barcode"))))
ui <- fluidPage(
titlePanel("Scan Sample Barcode"),
mainPanel(
rHandsontableOutput("scanBarcode")
)
)
server <- function(input, output) {
output$scanBarcode <- renderRHandsontable(rhandsontable(DF) %>%
hot_cols(renderer = "function(instance, td, row, col, prop, value, cellProperties)
{Handsontable.TextCell.renderer.apply(this, arguments);
if (col == 0 & row == 0 ) {td.focus();}")
)
}
shinyApp(ui = ui, server = server)
【问题讨论】:
-
如果您提供最少的构建代码,您可能会得到更多帮助。
-
我按照建议添加了代码。我想添加 JavaScript 作为渲染器。
-
谢谢指出错误。我按照建议更新了代码。
标签: javascript r shiny rhandsontable