【发布时间】:2014-11-04 04:03:07
【问题描述】:
我想创建一个可以插入数值的矩阵。另外,我希望可见的行数取决于 actionButton。只要我的矩阵中有 NA,下面的代码就可以正常工作,但如果我用一些 numericInput 替换 NA,则不能。
这里是 ui.R:
shinyUI(
pageWithSidebar(
headerPanel("test"),
sidebarPanel(
actionButtonGreen("test","add a row")),
mainPanel(
uiOutput("value"))
)
)
这里是服务器。R:
shinyServer(function(input,output){
observe({
if (input$test == 0)
return()
isolate({
output$value <-renderTable(
mdat <- matrix(NA, nrow = input$test, ncol = 2, byrow = TRUE)
)
##If I change the NAs to a vector of numericInput, I obtain the following error
##Error: number of items to replace is not a multiple of replacement length
##That's when I replace the NA in the above matrix with
##c(numericInput(inputId="1",label="",value="2"),
## numericInput(inputId="2",label="",value="2"),
## numericInput(inputId="3",label="",value="2"),
## numericInput(inputId="4",label="",value="2"))
})})
} )
任何建议将不胜感激。
干杯
【问题讨论】: