0
绘制图形时
我有我从谷歌分析提取下列数据帧不能强迫类“”直方图“”一个data.frame错误闪亮
ga_data <- google_analytics_4(viewId = my_id,
date_range = c(Sys.Date()-7, Sys.Date()-1),
metrics = c("sessions","pageviews",
"entrances","bounces"),
dimensions = c("date","deviceCategory",
"channelGrouping"),
anti_sample = TRUE)
现在我想展示图在Shiny应用程序中的ga_data。因此,我有以下代码:
library(shiny)
library(ggplot2)
ui <- fluidPage(
titlePanel("Shiny Text"),
sidebarLayout(
sidebarPanel(
selectInput(inputId = "dataset",
label = "Choose a dataset:",
choices = c("ga_data")),
numericInput(inputId = "obs",
label = "Number of observations to view:",
value = 10)
),
mainPanel(
verbatimTextOutput("summary"),
tableOutput("view")
)
)
)
server <- function(input, output) {
ga_data <- google_analytics_4(viewId = 156004565,
date_range = c(Sys.Date()-7, Sys.Date()-1),
metrics = c("sessions","pageviews",
"entrances","bounces"),
dimensions = c("date","deviceCategory",
"channelGrouping"),
anti_sample = TRUE)
datasetInput <- reactive({
switch(input$dataset,
"ga_data" = ga_data)
})
output$view <- renderTable({
hist(ga_data$sessions)
})
}
shinyApp(ui = ui, server = server)
然而,当我运行它,我得到以下错误:
cannot coerce class ""histogram"" to a data.frame
但是,这是奇怪的原因,当我想使数据帧的正常情节,它的工作。所以这个问题可能与Shiny有关。
有什么想法可以在这里出错?
你为什么在'tableOutput'中使用'renderTable()'来绘制图?那些是表格。你不想''plotOutput'' renderPlot()'? – MrFlick