简体   繁体   English

使用googleVis在本地运行时未在R Shiny中生成图表

[英]Chart not generated in R shiny when run locally using googleVis

These are the codes for my UI and server. 这些是我的UI和服务器的代码。 The issue that I am facing is that when the app is run locally the charts are not being generated. 我面临的问题是,当应用程序在本地运行时,不会生成图表。

ui.R 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 server.R

library(googleVis)
require(googleVis)
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')
  })

}
)

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; 首先,您应该在server.R和ui.R中都打开一个闪亮的库; it looks like you reproduced googleVis twice in server.R. 看来您在server.R中复制了googleVis两次。 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. 另外,我发现您在htmlOutput('view')中将'v'大写,但这应该与server.R中的output $ view路径匹配(未大写)。

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 ). 通常使用单选按钮,以便将它们的输入馈送到server.R中的反应性环境以更改数据集或其他一些参数(请参见闪亮的教程或该示例: 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 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 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. 希望能有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM