//我共享了一段代码,我收到错误。 在这里,我想传递日期范围,并从我的数据框中的查询中获取数据
output$DateRange <- renderText(
if(USER$Logged==TRUE){
//从这里获取输入日期范围
validate(
need(as.character(Sys.Date()) >= input$dates[1],
"Start Date should be less than or equal to Current Date"
)
)
validate(
need(input$dates[2] <= as.character(Sys.Date()) && input$dates[2] >= input$dates[1], "End Date should be greater than Start date and less than Current Date"
))
})
//i am passing date range from here in my query but i am getting a error while passing datesetFirst and datesetSecond
datesetFirst <- reactive(input$dates[1])
datesetSecond <- reactive(input$dates[2])
if (!is.null(datesetFirst) && !is.null(datesetSecond))
{
//这是我希望在从这里传递日期范围后执行的查询我希望根据输入范围获取数据
resultset =paste("SELECT SET2.AREA_NAME,SET2.PROD_NM,
SET2.TherapeuticClass,set2.TOTAL,
ROUND(((set2.TOTAL/SET3.TOTAL)*100),2) as SHARE
FROM (select retail_store_area_wise.area_name AS AREA_NAME,
set1.PROD_NM AS PROD_NM,sum(set1.TOTAL) AS TOTAL,
set1.TH_CLASS_1 AS TH_1,
set1.TH_CLASS_2 AS TH_2,
set1.TH_CLASS_3 AS TH_3,
set1.TH_CLASS_4 AS TH_4,
CONCAT(CONCAT(CONCAT(CONCAT( set1.TH_CLASS_1, ','),set1.TH_CLASS_2),','),CONCAT(CONCAT( set1.TH_CLASS_3, ','),set1.TH_CLASS_4) ) as TherapeuticClass
from
(select
retail_store_prod.TH_CLASS_4 as TH_CLASS_4,
retail_store_prod.TH_CLASS_3 as TH_CLASS_3,
retail_store_prod.TH_CLASS_2 as TH_CLASS_2,
retail_store_prod.TH_CLASS_1 as TH_CLASS_1,
retail_store_prod.store_id as store_id ,
retail_store.str_nm,
retail_Str_sales_detail.prod_nm as PROD_NM,
round(sum (retail_Str_sales_detail.total),2) AS TOTAL
from
retail_str_sales_detail ,
retail_store_prod,retail_store
where
retail_store_prod.prod_nm = retail_str_sales_detail.prod_nm and
retail_store_prod.store_id=retail_str_sales_detail.store_id and
retail_store.store_id = retail_store_prod.store_id AND
retail_str_sales_detail.SALE_DATE BETWEEN //while passing the date range here i am getting the error**'",datesetFirst,"'** AND **'",datesetSecond,"'**
AND retail_store_prod.TH_CLASS_4 != 'NULL'
AND retail_store_prod.TH_CLASS_3 != 'NULL'
AND retail_store_prod.TH_CLASS_2 != 'NULL'
AND retail_store_prod.TH_CLASS_1 != 'NULL'
AND retail_store_prod.TH_CLASS_4 != ''
AND retail_store_prod.TH_CLASS_3 != ''
AND retail_store_prod.TH_CLASS_2 != ''
AND retail_store_prod.TH_CLASS_1 != ''
GROUP BY
retail_store_prod.TH_CLASS_4 ,
retail_store_prod.TH_CLASS_3 ,
retail_store_prod.TH_CLASS_2 ,
retail_store_prod.TH_CLASS_1 ,
retail_Str_sales_detail.prod_nm ,retail_store.str_nm,
retail_store_prod.store_id
order by retail_Str_sales_detail.prod_nm,
retail_store_prod.TH_CLASS_4 ,
retail_store_prod.TH_CLASS_3 ,
retail_store_prod.TH_CLASS_2 ,
retail_store_prod.TH_CLASS_1 ,retail_store.str_nm,
round(sum (retail_Str_sales_detail.total),2) desc) as set1, retail_store_area_wise
where set1.store_id = retail_store_area_wise.store_id
group by set1.PROD_NM,
set1.TH_CLASS_1,
set1.TH_CLASS_2,
set1.TH_CLASS_3,
set1.TH_CLASS_4,
retail_store_area_wise.area_name,CONCAT(CONCAT(CONCAT(CONCAT( set1.TH_CLASS_1, ','),set1.TH_CLASS_2),','),CONCAT(CONCAT( set1.TH_CLASS_3, ','),set1.TH_CLASS_4) )
order by retail_store_area_wise.area_name,set1.PROD_NM) as SET2
FULL OUTER JOIN
(select retail_store_area_wise.area_name AS AREA_NAME,sum(set1.TOTAL) AS TOTAL,
set1.TH_CLASS_1 AS TH_1,
set1.TH_CLASS_2 AS TH_2,
set1.TH_CLASS_3 AS TH_3,
set1.TH_CLASS_4 AS TH_4,
CONCAT(CONCAT(CONCAT(CONCAT( set1.TH_CLASS_1, ','),set1.TH_CLASS_2),','),CONCAT(CONCAT( set1.TH_CLASS_3, ','),set1.TH_CLASS_4) ) as TherapeuticClass
from
(select
retail_store_prod.TH_CLASS_4 as TH_CLASS_4,
retail_store_prod.TH_CLASS_3 as TH_CLASS_3,
retail_store_prod.TH_CLASS_2 as TH_CLASS_2,
retail_store_prod.TH_CLASS_1 as TH_CLASS_1,
retail_store_prod.store_id as store_id ,
retail_store.str_nm,
retail_Str_sales_detail.prod_nm as PROD_NM,
round(sum (retail_Str_sales_detail.total),2) AS TOTAL
from
retail_str_sales_detail ,
retail_store_prod,retail_store
where
retail_store_prod.prod_nm = retail_str_sales_detail.prod_nm and
retail_store_prod.store_id=retail_str_sales_detail.store_id and
retail_store.store_id = retail_store_prod.store_id AND
retail_str_sales_detail.SALE_DATE BETWEEN '",datesetFirst,"' AND '",datesetSecond,"'
AND retail_store_prod.TH_CLASS_4 != 'NULL'
AND retail_store_prod.TH_CLASS_3 != 'NULL'
AND retail_store_prod.TH_CLASS_2 != 'NULL'
AND retail_store_prod.TH_CLASS_1 != 'NULL'
AND retail_store_prod.TH_CLASS_4 != ''
AND retail_store_prod.TH_CLASS_3 != ''
AND retail_store_prod.TH_CLASS_2 != ''
AND retail_store_prod.TH_CLASS_1 != ''
GROUP BY
retail_store_prod.TH_CLASS_4 ,
retail_store_prod.TH_CLASS_3 ,
retail_store_prod.TH_CLASS_2 ,
retail_store_prod.TH_CLASS_1 ,
retail_Str_sales_detail.prod_nm ,retail_store.str_nm,
retail_store_prod.store_id
order by retail_Str_sales_detail.prod_nm,
retail_store_prod.TH_CLASS_4 ,
retail_store_prod.TH_CLASS_3 ,
retail_store_prod.TH_CLASS_2 ,
retail_store_prod.TH_CLASS_1 ,retail_store.str_nm,
round(sum (retail_Str_sales_detail.total),2) desc) as set1, retail_store_area_wise
where set1.store_id = retail_store_area_wise.store_id group by
set1.TH_CLASS_1,
set1.TH_CLASS_2,
set1.TH_CLASS_3,
set1.TH_CLASS_4,
retail_store_area_wise.area_name,
CONCAT(CONCAT(CONCAT(CONCAT( set1.TH_CLASS_1, ','),set1.TH_CLASS_2),','),CONCAT(CONCAT( set1.TH_CLASS_3, ','),set1.TH_CLASS_4) )
order by retail_store_area_wise.area_name) AS SET3
ON SET3.AREA_NAME= SET2.AREA_NAME AND
SET3.TH_1= SET2.TH_1 AND
SET3.TH_2 = SET2.TH_2 AND
SET3.TH_3 = SET2.TH_3 AND
SET3.TH_4 = SET2.TH_4");
querytherapeutic1= reactive({dbGetQuery(conn,resultset)})
biztherapeuticproduct1= data.frame(
Area= querytherapeutic1$AREA_NAME,
THERAPEUTIC_CLASS= querytherapeutic1$THERAPEUTICCLASS,
Market_Share= as.numeric(as.character(querytherapeutic1$SHARE)),
Product= querytherapeutic1$PROD_NM,
Total = as.numeric(as.character(querytherapeutic1$TOTAL)),
stringsAsFactors = FALSE
)}
答案 0 :(得分:0)
您的错误消息来自代码的这一部分
datesetFirst <- reactive(input$dates[1])
datesetSecond <- reactive(input$dates[2])
if (!is.null(datesetFirst) && !is.null(datesetSecond))
reactive返回一个函数而不是一个值,因此你需要将代码更改为
datesetFirst <- reactive(input$dates[1])
datesetSecond <- reactive(input$dates[2])
if (!is.null(datesetFirst()) && !is.null(datesetSecond()))
当然还有查询以及
"retail_str_sales_detail.SALE_DATE BETWEEN '",datesetFirst(),"' AND '",datesetSecond(),"'