使空单元格为package:rhandsontable的表输入整数
我想在rhandsontable中创建空单元格,但是如果我们使用使空单元格为package:rhandsontable的表输入整数,r,shiny,rhandsontable,R,Shiny,Rhandsontable,我想在rhandsontable中创建空单元格,但是如果我们使用NA,那么它将是复选框,而不是包rhandsontable表中的空单元格 谢谢你,@Ismirsehegal。 在下面的代码中,我们可以创建一个单元格为空的表 使用NA\u integer\u代替NA,我们可以生成一个空单元格 解决@ismirsehegal问题的方法 library(rhandsontable) library(shiny) foo <- function(M =
NA
,那么它将是复选框,而不是包rhandsontable表中的空单元格
谢谢你,@Ismirsehegal。 在下面的代码中,我们可以创建一个单元格为空的表 使用
NA\u integer\u
代替NA
,我们可以生成一个空单元格
解决@ismirsehegal问题的方法
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()
库(rhandsontable)
图书馆(闪亮)
foo您需要使用NA\u integer\u
而不是NA
。对于NA
而言,结果向量的类型为“logical”,这会导致复选框的显示
请参见以下内容:
library(rhandsontable)
library(shiny)
foo <- function(M = 2,
Q = 3,
C = 4) {
DF <- data.frame(
m = 1, # m_q_c_vector_from_M_Q_C(M, Q, C)$m,
q = 2, # m_q_c_vector_from_M_Q_C(M, Q, C)$q,
c = 3, # m_q_c_vector_from_M_Q_C(M, Q, C)$c,
h = rep(NA_integer_, M * Q * C),
f = rep(NA_integer_, M * Q * C)
)
ui <- shiny::fluidPage(
shiny::tags$head(
shiny::tags$link(rel = "stylesheet", type = "text/css", href = "styles.css")
),
# Color
shiny::sidebarLayout(
shiny::sidebarPanel(
shiny::sliderInput(
"Number_of_MCMC_samples",
"Number of MCMC samples:",
min = 10,
max = 11111,
value = 111
),
shiny::h4(shiny::helpText(" Larger is better."))
,
shiny::sliderInput(
"Number_of_MCMC_chains",
"Number of MCMC chains:",
min = 1,
max = 4,
value = 1
),
shiny::sliderInput(
"Number_of_lesions",
"Number of lesions:",
min = 1,
max = 1111,
value = 259#
),
shiny::sliderInput(
"Number_of_images",
"Number of images:",
min = 1,
max = 1111,
value = 57
),
shiny::sliderInput(
"C",
"Number of C:",
min = 1,
max = 11,
value = 3
),
shiny::sliderInput(
"M",
"Number of M:",
min = 1,
max = 7,
value = 4
),
shiny::sliderInput(
"Q",
"Number of Q:",
min = 1,
max = 7,
value = 5
),
shiny::h1("Data"),
shiny::h4(
shiny::helpText("Right-click on the table to delete/insert rows.")
),
shiny::h4(shiny::helpText("Double-click on a cell to edit")),
rhandsontable::rHandsontableOutput("hot"),
# Table of h and f ###########################################################
shiny::h5(shiny::helpText(" h = hit = True Positive = TP.")),
shiny::h5(shiny::helpText(" f = false alarms = False Positive = FP."))
),
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()
库(rhandsontable)
图书馆(闪亮)
foo您的代码不可复制,来自_m_q_c
的函数m_q_c_vector_丢失。谢谢@ismirsehegal,我的示例代码是多余的,我减少了它。