as.vector(x, "character") 中的错误:无法将类型 'closure' 强制转换为类型 'character' 的向量
Error in as.vector(x, "character") : cannot coerce type 'closure' to vector of type 'character'
//我分享了一段出现错误的代码。
在这里我想传递日期范围并从我的数据框中的查询中获取数据
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
)}
您的错误消息来自这部分代码
datesetFirst <- reactive(input$dates[1])
datesetSecond <- reactive(input$dates[2])
if (!is.null(datesetFirst) && !is.null(datesetSecond))
响应式 returns 函数不是值,因此您需要将代码更改为此
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(),"'
//我分享了一段出现错误的代码。 在这里我想传递日期范围并从我的数据框中的查询中获取数据
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
)}
您的错误消息来自这部分代码
datesetFirst <- reactive(input$dates[1])
datesetSecond <- reactive(input$dates[2])
if (!is.null(datesetFirst) && !is.null(datesetSecond))
响应式 returns 函数不是值,因此您需要将代码更改为此
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(),"'