【发布时间】:2019-03-28 16:13:38
【问题描述】:
在我的小闪亮应用程序中,我问用户:你想把你的时间序列分成多少个时间段?例如,用户选择 3。 我想使用此输入来获取固定的日期向量,并使用户可以从中选择时间段 1(在选择框 1 中)和时间段 2(在选择框 2 中)的所需最后日期。 (时间段 3 的最后一个日期将是最后一个日期,所以我不需要问)。
我不知道该怎么做。我明白,因为我事先不知道所需的时间段数,所以我必须创建一个列表。但是我如何从这些选择框中收集输入?
非常感谢!
library(shiny)
### UI #######################################################################
ui = shinyUI(fluidPage(
titlePanel("Defining time periods"),
# Sidebar:
sidebarLayout(
sidebarPanel(
# Slider input for the number of time periods:
numericInput("num_periodsnr", label = "Desired number of time periods?",
min = 1, max = 10, value = 2),
uiOutput("period_cutpoints")
),
# Show just the number of periods so far.
mainPanel(
textOutput("nr_of_periods")
)
)
))
### SERVER ##################################################################
server = shinyServer(function(input, output, session) {
library(lubridate)
output$nr_of_periods <- renderPrint(input$num_periodsnr)
# Define our dates vector:
dates <- seq(ymd('2016-01-02'), ymd('2017-12-31'), by = '1 week')
# STUCK HERE:
# output$period_cutpoints<-renderUI({
# list.out <- list()
# for (i in 1:input$num_periodsnr) {
# list.out[[i]] <- renderPrint(paste0("Sometext", i), ,
# )
# }
# return(list.out)
# })
})
# Run the application
shinyApp(ui = ui, server = server)
【问题讨论】: