【发布时间】:2019-11-05 18:47:06
【问题描述】:
我正在使用动态 UI,并希望选择默认值和输入,和隔离以下值。
在下面的例子中,我可以隔离默认值(value = isolate(input$dynamic)),但我不能设置默认值(不同于最小值)。
有没有办法同时做(设置值和隔离之后)?
library(shiny)
ui <- fluidPage(
fluidRow(
textInput("label", "labelasd"),
selectInput("type_of_pe", "Type of policy estimate", c("type 1", "type 2", "type 3")),
uiOutput("data_in")
)
)
server <- function(input, output, session) {
output$data_in <- renderUI({
output <- tagList()
output [[1]] <- sliderInput("dynamic", input$label, value = isolate(input$dynamic), min = 0, max = 100)
output [[2]] <- sliderInput("dynamic", input$label, value = isolate(input$dynamic) * 20, min = 5, max = 20)
if (input$type_of_pe == "type 1") {
lapply( 1, function(x) output[[x]] )
} else if (input$type_of_pe == "type 2") {
lapply( 2, function(x) output[[x]] )
} else if (input$type_of_pe == "type 3") {
lapply( c(1,2), function(x) output[[x]] )
}
})
}
shinyApp(ui = ui, server = server)
【问题讨论】:
-
请提供可以运行的完整最小示例
-
上面的例子现在在我的机器上运行。如果您仍然无法运行,请告诉我。