我有一个简单的网络应用程序,有两组输入:
我希望参数的标签与所选的分布相对应。我有这个工作,但是当我第一次加载页面时收到警告,似乎是由于下拉列表中的默认选择值没有快速注册。
我得到的警告是:
Warning: Error in [[: attempt to select less than one element in get1index
Stack trace (innermost first):
84: %AND%
83: tag
82: tags$div
81: div
80: textInput
79: renderUI [H:\Repos\DiscreteEventSimulation\debugdefaultdrop/app.R#34]
78: func
77: origRenderFunc
76: output$selparams
1: runApp
这是一个MWE:
library(shiny)
ui <- fluidPage(
uiOutput("seldist"),
uiOutput("selparams")
)
server <- function(input, output) {
DISTS <- list("Normal"=list(params=c("mean", "variance"),
short="N"),
"Weibull"=list(params=c("scale", "shape"),
short="Wei"),
"Uniform"=list(params=c("lower", "upper"),
short="U"),
"Log-Normal"=list(params=c("location", "scale"),
short="logN")
)
output$seldist <- renderUI({
selectInput("seldist", "Distribution", choices=names(DISTS), selected="Normal")
})
output$selparams <- renderUI({
item_list <- list()
item_list[[1]] <- textInput("param1", DISTS[[input$seldist]]$params[1], "")
item_list[[2]] <- textInput("param2", DISTS[[input$seldist]]$params[2], "")
do.call(tagList, item_list)
})
}
shinyApp(ui = ui, server = server)