[.data.table中出错:我已计算为闭包类型。R中应为逻辑、整数或双精度
我一直在尝试编写一个优化电力生产设施的代码,该设施必须是R中的web应用程序。我正在使用shiny软件包解决这个问题。在代码的服务器部分,必须进行一些计算,因此我为这个问题编写了一些方程式。这是我的shinyServer部分[.data.table中出错:我已计算为闭包类型。R中应为逻辑、整数或双精度,r,shiny,data.table,R,Shiny,Data.table,我一直在尝试编写一个优化电力生产设施的代码,该设施必须是R中的web应用程序。我正在使用shiny软件包解决这个问题。在代码的服务器部分,必须进行一些计算,因此我为这个问题编写了一些方程式。这是我的shinyServer部分 function(input, output){ abc <- reactive({ which(paste(input$tarih, input$zaman, sep = " ") == data$Tarih.ve.Saat) def <
function(input, output){
abc <- reactive({
which(paste(input$tarih, input$zaman, sep = " ") == data$Tarih.ve.Saat)
def <- reactive({
which(month(input$tarih) == aylıkdata$Ay)
})
})
output$baseload <- renderPrint(
((as.numeric(data[abc(),3]) * input$paste("bload", def(), sep ="")) - (input$paste("gaz", def(), sep = "")*input$gazfiyatı) - (input$ürtvergi*input$paste("bload", def(), sep ="")))
)
output$mkud <- renderPrint(
((as.numeric(data[abc(),3]) * input$mkudüretim) - (input$mkudgazkullanımı*input$gazfiyatı) - (input$ürtvergi*input$mkudüretim))
)
output$stup <- renderPrint(
((as.numeric(data[abc(),3]) * input$supüretim) - (input$supgazkullanımı*input$gazfiyatı) - (input$ürtvergi*input$supüretim))
)
output$sdown <- renderPrint(
((as.numeric(data[abc(),3]) * input$sdownüretim) - (input$sdowngazkullanımı*input$gazfiyatı) - (input$ürtvergi*input$sdownüretim))
)
}
)
功能(输入、输出){
abc尝试一下这一点,因为我没有数据来确认/否认这是否有效…(没有花费比我想要的更多的时间:p)
我的感觉是你不能做data[abc(),3]
,因为它不希望在data.table中有一个反应式表达式。我会尝试创建一个反应式数据集,然后改用它。我不能完全解释你的代码,因为你在反应式中有反应式……这行吗
这可能会失败,因为我没有太多地使用shiny,但希望这个想法可以建立在它的基础上
# instead try to return the reactive data object
reactive_data <- reactive({
con <- which(paste(input$tarih, input$zaman, sep = " ") == data$Tarih.ve.Saat)
data[con,]
})
#... other things eg the def <- reactive(.. command
# instead, call the reactive data that's the data.table and use [,3] to filter or instead just put [,3] in the output above if nothing else is ever used
output$mkud <- renderPrint(
((as.numeric(reactive_data()[,3]) * input$mkudüretim) - (input$mkudgazkullanımı*input$gazfiyatı) - (input$ürtvergi*input$mkudüretim))
)
#而是尝试返回反应式数据对象
反应性数据