0
我想上传一个列名为Time
的数据集。然后,代码找到Time
列的最大值,并将其除以4以找出有多少个大小为4的区间,然后在selectInput
中打印出该序列。这是我的代码。它的作品,但在max(data()$Time)
有一个小错误,我不明白为什么它给-inf
。错误说no non-missing arguments to max; returning -Inf
如何读取和更新'selectInput'的值
下面是代码:
library(shiny)
ui <- fluidPage(
fileInput(inputId = "uploadcsv","", accept = '.csv'),
selectInput("select", label = h3("Select box"),
choices = "",
selected = 1)
)
server <- function(input, output, session) {
data <- reactive({
infile <- input$uploadedcsv
if (is.null(infile))
return(NULL)
read.csv(infile$datapath, header = TRUE, sep = ",")
})
observe({
if (max(data()$Time) %% 4 == 0){
numberofinterval <- max(data()$Time) %/% 4
} else {
numberofinterval <- (max(data()$Time) %/% 4)+1
}
NumPeriod <- seq(0, numberofinterval)
updateSelectInput(session, inputId = "select",
choices = NumPeriod,
selected = NumPeriod)
})
}
shinyApp(ui = ui, server = server)
你可以尝试格式化你的变量作为日期'as.Date()',但除非你分享你的CSV,它或多或少的随机猜测,... – BigDataScientist