gpt4 book ai didi

不允许从 shinyoutput 对象读取对象

转载 作者:行者123 更新时间:2023-12-01 14:06:15 24 4
gpt4 key购买 nike

我正在使用以下平台和 R 版本:

平台 x86_64-apple-darwin10.8.0
version.string R 版本 3.0.3 (2014-03-06)

我是 shiny 的新手,我正在尝试使用 rWBclimate 数据集将一个简单的应用程序放在一起,它是 R 中的一个包:

http://cran.r-project.org/web/packages/rWBclimate/rWBclimate.pdf

我收到以下错误:

$.shinyoutput 错误(输出,gvis): 不允许从 shinyoutput 对象读取对象。

使用以下脚本时。ui.R

library(shiny)
suppressPackageStartupMessages(library(googleVis))

shinyUI(pageWithSidebar(
# Application title
headerPanel("Global Temperature"),

#sidebar with controls to select var to plot year
sidebarPanel(
selectInput("fromyr", "Select Years:", choices=c("1920", "1940","1960", "1980"))
),
mainPanel(
htmlOutput("gvis")#,
)

)
)

和server.R

library(shiny)
#install.packages("rWBclimate")
library(rWBclimate)
library(ggplot2)
library(rCharts)
suppressPackageStartupMessages(library(googleVis))

countries <-c("USA","BRA","CAN","YEM")

# get temperature data for ensembles
st=1900
en=2100
data_df_all <- get_ensemble_temp(countries, type="annualavg", start=st, end=en)

data_df<-subset(data_df_all,data_df_all$percentile==50) #subset to median percentile
data_df<-subset(data_df, select=-percentile)
data_df<-subset(data_df, data_df$scenario!="b1")
data_df<-subset(data_df, select=-scenario)
data_df<-subset(data_df, data_df$fromYear==1920)

shinyServer(function(input, output){

#df<-reactive({
# switch(subset(data_df, data_df$fromYear==input$fromyr),
# "1920"= 1920,
# "1940" = 1940,
# "1960" = 1960,
# "1980" = 1980)
#dfi<-subset(data_df, data_df$fromYear==input$fromyr)
#subset(data_df, data_df$fromYear==1920)
#data_df[data_df$fromYear == input$fromyr, ]
#subset(data_df, data_df$scenario==input$scenar)
#subset(alldat, alldat$fromYear==input$fromyr)
# })

output$gvis < renderGvis({
# gvisGeoChart(dat=df(), locationvar="locator", colorvar="data")
gvisGeoChart(data_df, locationvar="locator", colorvar="data")
})
})

任何见解都会很棒。我尝试使用 react 语句,并将文件直接放入 gvisGeoChart,就像上面的版本一样。

最佳答案

您只是在 server.R 文件的末尾缺少一个“-”。如果你仔细观察你的 output$gvis 你会注意到你没有分配 output$gvis 而是实际上将它与你渲染的 Gvis 对象进行比较 <运算符(这就是为什么您会收到有关从输出中读取对象的错误的原因)。只需更改 output$gvis < renderGvis({...output$gvis <- renderGvis({...一切都应该工作正常。

关于不允许从 shinyoutput 对象读取对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26285470/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com