Dataframe R中的反应对象和函数
我正在使用Shiny R,但我不知道如何解决服务器中的问题。未找到“climate2”和“weather10”对象。很可能,“latlong”和“comp”对象显示出问题,但我不知道。“forecast10day”函数的“latlong”参数不适用于我的“latlong”对象,“semi_join”函数不适用于我的“comp”对象。我只复制了代码的一部分,因为它很长 非常感谢 全球RDataframe R中的反应对象和函数,dataframe,shiny-server,rwunderground,Dataframe,Shiny Server,Rwunderground,我正在使用Shiny R,但我不知道如何解决服务器中的问题。未找到“climate2”和“weather10”对象。很可能,“latlong”和“comp”对象显示出问题,但我不知道。“forecast10day”函数的“latlong”参数不适用于我的“latlong”对象,“semi_join”函数不适用于我的“comp”对象。我只复制了代码的一部分,因为它很长 非常感谢 全球R # Climate climate <- cbind(tmin,tmax[,-c(1:3)],rhpm[,
# Climate
climate <- cbind(tmin,tmax[,-c(1:3)],rhpm[,-c(1:3)],rham[,-c(1:3)])
names(climate) <- c("Long","Lat","Month","Tmin","Tmax","RHmin","RHmax")
head(climate,2)
#气候
气候如果你想在不同的反应函数中使用变量,你必须将它们定义为反应值或反应函数。必须像functionName()一样调用反应函数如果要在不同的反应函数之间使用变量,则必须将它们定义为反应值或反应函数。必须像functionName()一样调用被动函数
latlong <- reactive({
latlong <- as.character(c(input$Lat,input$Long))
weather.10 <- forecast10day(set_location(lat_long = paste(latlong,collapse = ",")))
names(weather.10)[names(weather.10) == "temp_high"] <- "Tmax"
names(weather.10)[names(weather.10) == "temp_low"] <- "Tmin"
weather.10$Tmax <- fahrenheit.to.celsius(weather.10$Tmax, round = 0)
weather.10$Tmin <- fahrenheit.to.celsius(weather.10$Tmin, round = 0)
})
#Outputs
output$text0 <- renderText({
if(input$Irrigation =="No")
if(round(mean(min(weather.10$Tmin))) > 17 && round(mean(max(weather.10$Tmax))) < 35 && round(mean(min(weather.10$ave_humidity))) > 34 && round(mean(max(weather.10$ave_humidity))) < 87)
{
paste("The combination Biological and Chemical control is recomended in Drought or Rainy period.")
}else{
paste("Biological or chemical control or both may be inefficient and there are low risk of epidemics")
}
})
comp <- reactive ({
#Selecting options of user
comp <- data.frame(input$Long, input$Lat,input$Month)
climate <- semi_join(climate, comp, by=c("Long","Lat","Month"))
climate2 <- data.frame(unique(climate$Long),unique(climate$Lat),unique(climate$Month),round(mean(climate$Tmin)),
round(mean(climate$Tmax)),round(mean(climate$RHmin)),
round(mean(climate$RHmax)))
names(climate2) <- c("Long", "Lat","Mont","Tmin","Tmax","RHmin","RHmax")
})
output$text1 <- renderText({
if(input$Irrigation =="50-60%")
if(climate2$Tmax > 17 && climate2$Tmin < 35 && climate2$RHmin > 34 && climate2$RHmax < 87)
{
paste("The combination Biological and Chemical control is recomended.")
}else{
paste("Biological or chemical control or both may be inefficient. You can see more information in FORECASTING.")
}
})
ui <- fluidPage(theme = shinytheme("superhero"),
h3("Information system to control Dry Root Rot in Common Beans"),
sidebarLayout(sidebarPanel(
numericInput("Long", label = h3("Longitude:"), value = -49),
numericInput("Lat", label = h3("Latitude:"), value = -17),
actionButton("recalc", "Show point"),
selectInput(inputId = "Irrigation",label = "Irrigation (Soil Available Water)",
choices = c("No","50-60%","80-90%","110-120%","140-150%"),
selected = "80-90%"
),
selectInput(inputId = "Month", label = "Current Month", choices = c("Jan","Feb","March","April","May","June","July",
"Aug","Sep","Oct","Nov","Dec")),