我在 R 中制作了一个 Shiny 应用程序,向用户显示类似 Excel 的网格。该excelR包是 JS 包JSpreadsheet的包装器。这个包自动将行号放在最左边的列中。我不想要他们。
通过深入研究 JavaScript,我终于能够弄清楚如何使用 actionButton 通过发送 JS 命令来删除行号:
library(shiny)
library(excelR)
library(shinyjs)
jsCode <- "shinyjs.hideindex = function(params) {document.getElementById('table').jexcel.hideIndex();}"
ui <- fluidPage(
useShinyjs(),
extendShinyjs(text = jsCode, functions = "hideindex"),
excelOutput("table", height = 175),
actionButton('hide_button', 'Hide Index Column')
)
server <- function(input, output, session){
output$table <- renderExcel({
excelTable(data = head(iris),
columns = data.frame(title = names(iris),
type = c('numeric', 'numeric', 'numeric', 'numeric', 'text')))
})
onclick("hide_button", js$hideindex())
}
shinyApp(ui, server)
但我真的很想让表格在没有索引列(行号)的情况下自动呈现。我尝试使用观察事件(以及许多其他东西)来监视 中的变化input$table,但是在编辑表之前似乎没有创建输入。