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