在 Shiny 应用程序的 excelR 小部件中隐藏索引列(行号)
我用 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)
但我真的很想让表格在没有索引列(行号)的情况下自动呈现。我尝试使用observeEvents(以及许多其他东西)来监视input$table
中的更改,但在编辑表之前似乎不会创建输入。
I make making a Shiny app in R that shows the user an Excel-like grid. The excelR
package is a wrapper for a JS package JSpreadsheet. This package automatically puts row numbers in the left-most column. I do not want them.
By digging into the JavaScript, I was finally able to figure out how to use an actionButton to remove the row numbers by sending a JS command:
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)
But I would really like to have the table render automatically without the index column (row numbers). I tried to use observeEvents (and many, many other things) that watched for changes in input$table
, but the input does not seem to get created until the table is edited.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我修改了您的示例以使其更加离散,但是每次有人修改您的应用程序时它都会运行(由于
observe()
函数)。最好只在应用程序启动时运行它,但我还没有解决它。
I modified your example to make it more discrete, however it will run every time someone modify your app (because of the
observe()
function).It could be better to run this only at app start but I didn't solve it yet.