Chart not generated in R shiny when run locally using googleVis

杀马特。学长 韩版系。学妹 提交于 2019-12-04 15:12:28

Looks like you have a couple things going wrong here. First, you should have a library open to shiny in both server.R and ui.R; it looks like you reproduced googleVis twice in server.R. In addition I found you capitalized the 'v' in htmlOutput('view'), but this should match the output$view path in server.R which is not capitalized.

On top of this the radio buttons seem superfluous or I do not understand the intent. Typically radio buttons are used so that their input can be fed to a reactive environment in server.R to change a dataset or some other parameter (see shiny tutorial or this example: https://github.com/rstudio/shiny-examples/blob/master/006-tabsets/server.R).

Code below will produce the plot and I have left the radio buttons even though they serve no purpose.

ui.R

library(googleVis)
library(shiny)

shinyUI(fluidPage(
  titlePanel(" Tool"),
  sidebarLayout(
    sidebarPanel(
      radioButtons(inputId="choice", label="What would you like to see?", 
                   choices= c("Overall ","Individual"))
    ),
    mainPanel(
      htmlOutput("view")

    )
  )
))

server.R

library(googleVis)
library(shiny)

shinyServer(function(input, output) {

  n = 100 
  dates = seq(Sys.Date(), by = 'day', length = n)
  x = 10 * rnorm(n)
  y = 3 * x + 1 + rnorm(n)
  label = rep(LETTERS[1:4], each=25)
  label[1] = "D"

  my.data = data.frame(Date = dates, x, y, label)

  output$view <- renderGvis({
    gvisMotionChart(my.data, 
                    idvar ='label', 
                    xvar = 'x', 
                    yvar = 'y', 
                    timevar= 'Date')
  })

})

Be sure to also open it to a browser after the app is launched. Hope that helps.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!