使用googleVis在本地运行时未在R Shiny中生成图表 [英] Chart not generated in R shiny when run locally using googleVis
问题描述
这些是我的UI和服务器的代码.我面临的问题是,当应用程序在本地运行时,不会生成图表.
These are the codes for my UI and server. The issue that I am facing is that when the app is run locally the charts are not being generated.
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)
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')
})
}
)
推荐答案
似乎您在这里遇到了一些问题.首先,您应该在server.R和ui.R中都打开一个闪闪发光的库;看来您在server.R中复制了googleVis两次.另外,我发现您在htmlOutput('view')中将'v'大写,但这应该与server.R中的output $ view路径匹配(未大写).
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.
最重要的是,单选按钮似乎是多余的,或者我不明白其意图.通常使用单选按钮,以便将它们的输入馈送到server.R中的反应性环境以更改数据集或其他一些参数(请参见闪亮的教程或此示例:https://github.com/rstudio/shiny-examples/blob/master/006-tabsets/server.R ).
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.
这篇关于使用googleVis在本地运行时未在R Shiny中生成图表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!