I have a shiny app in which I can load a file. I wan't to extract the min and max date range from my file use these as input for a slider input.
我有一个闪亮的应用程序,我可以在其中加载文件。我不想从我的文件中提取最小和最大日期范围,使用这些作为滑块输入的输入。
Here is what I have so far
这是我到目前为止所拥有的
ui <- fluidPage(
dateRangeInput(inputId = "date", label = "Input a date range", start=textOutput("datemin") , end = textOutput("datemax"),"%d-%m-%y"))
)
server = function(input, output){
output$datemin <- renderText({as.character(as.Date(paste("01",as.character.Date(min(dataset()$date)),sep="-"),"%d-%y-%m"))})
output$datemax <- renderText({as.character(as.Date(paste("01",as.character.Date(max(dataset()$date)),sep="-"),"%d-%y-%m"))})
}
I know the outputs datemin and datemax are a bit tricky, this is because the "date" column in the dataset is a string such as "13-05" for may 2013 (the dataset is a summarized version with monthly means for some values)
我知道输出datemin和datemax有点棘手,这是因为数据集中的“日期”列是一个字符串,例如2013年5月的“13-05”(数据集是一个汇总版本,每月有一些值的含义)
Edit.
I've tried 3 different outputs for my date in order to check the format, and I display them as textoutput as follows :
为了检查格式,我为我的日期尝试了3种不同的输出,并将它们显示为textoutput,如下所示:
UI
textOutput("datemin1"),
textOutput("datemin2"),
textOutput("datemin3"),
Server
output$datemin1 <- renderText({(as.character.Date(min(dataset()$date)))})
output$datemin2 <- renderText({as.character(as.Date(paste("01",as.character.Date(min(dataset()$datem)),sep="-"),"%d-%y-%m"))})
output$datemin3 <- reactive({as.Date(as.yearmon(min(dataset()$datem)))})
The outputs are the following :
输出如下:
datemin1 : 14-01
datemin2 : 2014-01-01
datemin3 : 0014-01-01datemin1:14-01 datemin2:2014-01-01 datemin3:0014-01-01
But still when I try to use an output as an input value for my slider as follows :
但是当我尝试使用输出作为我的滑块的输入值时,仍然如下:
sliderInput("slider1", "Date Range",
min = textOutput("datemin2"), max=textOutput("datemax2"),
value = textOutput("datemax2")
),
I get this error : ERROR: non-numeric argument to binary operator
我收到此错误:错误:二元运算符的非数字参数
Thanks
1 个解决方案
#1
0
library(zoo)
includes yearmon
which is a class for representing monthly data. Please see code below, it converts 13-05
to 13-05-01
.
library(zoo)包括yearmon,它是表示月度数据的类。请参阅下面的代码,它将13-05转换为13-05-01。
library(shiny)
library(zoo)
dataset <- data.frame(minDate = c('13-05'), maxDate = c('14-05'))
if(interactive()){
shinyApp(
ui <- fluidPage(
sliderInput("slider1", "Date Range",
min = as.Date(as.yearmon(dataset$minDate)),
max = as.Date(as.yearmon(dataset$maxDate)),
value = as.Date(as.yearmon(dataset$minDate))
)
),
server = function(input, output){
}
)
}
#1
0
library(zoo)
includes yearmon
which is a class for representing monthly data. Please see code below, it converts 13-05
to 13-05-01
.
library(zoo)包括yearmon,它是表示月度数据的类。请参阅下面的代码,它将13-05转换为13-05-01。
library(shiny)
library(zoo)
dataset <- data.frame(minDate = c('13-05'), maxDate = c('14-05'))
if(interactive()){
shinyApp(
ui <- fluidPage(
sliderInput("slider1", "Date Range",
min = as.Date(as.yearmon(dataset$minDate)),
max = as.Date(as.yearmon(dataset$maxDate)),
value = as.Date(as.yearmon(dataset$minDate))
)
),
server = function(input, output){
}
)
}