Reading objects from shinyoutput object are not allowed

rshiny

I am using the following platform and version of R:

platform x86_64-apple-darwin10.8.0
version.string R version 3.0.3 (2014-03-06)

I am new to shiny and I am trying to put a simple app together using the rWBclimate data set, which is a package in R:

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

I get the following error:

Error in $.shinyoutput(output, gvis) :
Reading objects from shinyoutput object not allowed.

when using the scripts below.
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")#, 
  )  

)
)

and 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")
  })
})

Any insights would be great. I tried using the reactive statement, as well as putting the file directly into gvisGeoChart, as is the version above.

Best Answer

You are only missing a '-' at the end of your server.R file. If you look closely at your output$gvis you will notice that you are not assigning output$gvis but actually comparing it to your rendered Gvis object with the < operator (which is why you get the error about reading objects from output). Just change the output$gvis < renderGvis({... to output$gvis <- renderGvis({... and everything should work fine.

Related Topic