【发布时间】:2020-01-10 03:12:38
【问题描述】:
我想在 rhandsontable 中创建空单元格,但如果我们使用 NA,那么它将是复选框,而不是包 rhandsontable 表中的空单元格。
谢谢你,@ismirsehregal。 在下面的代码中,我们可以制作一个空单元格的表格..
使用NA_integer_ 代替NA,我们可以创建一个空单元格。
@ismirsehregal 的解决方案
library(rhandsontable)
library(shiny)
foo <- function(M = 2,
Q = 3,
C = 4) {
DF <- data.frame(
m = 1,
q = 2,
c = 3,
# To make empty cells, we should use NA_integer_ instead NA.
h= rep(NA_integer_, M * Q * C), # Here, we should use NA_integer_ instead NA
f = rep(NA_integer_, M * Q * C) # Here, we should use NA_integer_ instead NA
)
ui <- shiny::fluidPage(
shiny::sidebarLayout(
shiny::sidebarPanel(
rhandsontable::rHandsontableOutput("hot")
),
shiny::mainPanel()
)
)
server <- function(input, output) {
values <- shiny::reactiveValues()
## Handsontable
shiny::observe({
if
(!is.null(input$hot)) {
DF = rhandsontable::hot_to_r(input$hot)
} else {
if (is.null(values[["DF"]]))
DF <- DF
else
DF <- values[["DF"]]
}
values[["DF"]] <- DF
values[["dataList"]] <- list(
NL = input$Number_of_lesions,
NI = input$Number_of_images,
h = DF$h,
f = DF$f,
m = DF$m,
q = DF$q,
c = DF$c,
C = input$C,
M = input$M,
Q = input$Q
)
})
output$hot <- rhandsontable::renderRHandsontable({
DF <- values[["DF"]]
if (!is.null(DF))
rhandsontable::rhandsontable(DF,
stretchH = "all")
})
}
shiny::runApp(list(ui = ui, server = server))
return(invisible())
} # function
foo()
谢谢。
【问题讨论】:
-
您的代码不可重现,函数
m_q_c_vector_from_M_Q_C丢失。 -
谢谢@ismirsehregal,我的示例代码是多余的,我减少了它。
标签: r shiny rhandsontable