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