【发布时间】:2016-03-18 21:42:03
【问题描述】:
我想构建一个 R 闪亮的应用程序,它有一个动态输入,要求用户输入数字,然后基于该输入生成另外 4 个输入字段。这是我的想法。
library(shiny)
# Define UI for random distribution application
shinyUI(fluidPage(
# Application title
titlePanel("Calcs"),
# Sidebar with controls to select the random distribution type
# and number of observations to generate. Note the use of the
# br() element to introduce extra vertical spacing
sidebarLayout(
sidebarPanel(
numericInput("dorr", "How many inputs do you want",4),
i = i+1
while(input$dorr<i){
numericInput("S", "Number of simulations to run:", 10)
i=i+1
}
numericInput("S", "Number of simulations to run:", 10),
actionButton(inputId = "submit_loc",label = "Run the Simulation")
),
mainPanel(
)
)))
我知道上面的代码不起作用,但这是我的理由。我知道 Shiny 有条件语句,但我似乎找不到一个允许我生成预先指定数量的附加字段的语句。这甚至可能吗?
【问题讨论】:
-
您需要在服务器代码中使用
renderUI。有关示例,请参阅此页面shiny.rstudio.com/articles/dynamic-ui.html -
@warmoverflow 我已经意识到这一点,但我不明白如何使用它来动态创建预先指定数量的输入。