【发布时间】:2019-03-05 22:54:22
【问题描述】:
我对闪亮和 ggplot 还是很陌生,所以我不确定是什么导致了这个问题,我之前已经发布了这个代码的不同问题但是我遇到了一个新问题......当我运行代码时我的情节没有出现,而是出现错误:警告:FUN 中的错误:找不到对象“total_pigs”。
无论我在 selectInput "x"function 中选择什么选项,我都会收到此错误。
我在 app.R 文件所在的同一目录中有一个单独的 CSV 文件。 selectInput(s) 匹配 CSV 中的列和行,我希望我的代码可以简单地读取存储在其中的数据,这将生成我的绘图点。
library(shiny)
library(ggplot2)
path <- file.path("eu_pigs.csv", stringsAsFactors = FALSE)
ui <- fluidPage(
titlePanel("Breeding Numbers 2016 - 2018 (pig)"),
sidebarLayout(
sidebarPanel(
selectInput(inputId = "x",
label = "Pig Breeds:",
choices = c("total_pigs", "female_breeding_herd",
"in_pig_sows", "in_pig_gifts", "other_sows",
"maiden_gilts", "boars_for_service", "other_pigs"),
selected = "total_pigs"),
selectInput(inputId = "y",
label = "Year by year change:",
choices = c(2016, 2017, 2018, sep = ""),
selected = 2016)
),
mainPanel(
plotOutput(outputId = "scatterplot")
)
)
)
server <- (function(input, output) {
output$scatterplot <- renderPlot({
ggplot(data = read.csv("eu_pigs.csv")) +
aes_string(x = input$x, y = input$y) +
geom_point()
})
})
shinyApp(ui, server)
我附上我的 csv 文件的图像。
【问题讨论】:
-
你能提供数据吗?从图像看来,“total_pigs”是列中的一个值,在这种情况下,该图将不起作用,因为它希望获得一个列名
-
@DS_UNI 我的列名是:pig_breeds, 2016, 2017 & 2018 从 total_pigs 开始,所有行向下和跨越都是值,所以我的表格格式在 csv 而不是 shiny/ggplot2 中存在问题?
-
请不要在每次通话时使用
ggplot(data = read.csv("eu_pigs.csv")) +,一次就够了