【发布时间】:2019-09-06 14:15:13
【问题描述】:
我正在构建一个闪亮的应用程序,以允许我的一些非数据人员上传一些文件,一些转换、连接和摘要来自这些文件,并显示一些数字。
这里将使用一个文件和输出作为示例。我正在尝试在列上使用 dplyr 进行过滤条件,但在上传文件后出现此错误。
Listening on http://xxx.x.x.x:xxxx
Warning: Error in UseMethod: no applicable method for 'filter_' applied to an object of class "character"
[No stack trace available]
请注意,我并没有尝试做一个反应条件(还),只是试图过滤掉不需要产生所需输出的变量(在这种情况下是 2 因子饼图)。是过滤出错还是上传文件的方式有误?
用于过滤和 ggplot 的管道在有光泽的情况下工作正常。
library(shiny)
library(tidyverse)
library(scales)
# Define UI for data upload app ----
ui <- fluidPage(
# App title ----
titlePanel("Uploading Files"),
# Sidebar layout with input and output definitions ----
sidebarLayout(
# Sidebar panel for inputs ----
sidebarPanel(
# Input: Select a file ----
fileInput("file1", "Choose CSV File",
multiple = TRUE,
accept = c("text/csv",
"text/comma-separated-values,text/plain",
".csv"))
),
# Main panel for displaying outputs ----
mainPanel(
# Output: Data file ----
plotOutput(outputId = "plots")
)
)
)
和我的服务器
# Define server logic to read selected file ----
server <- function(input, output) {
observe({
data <- input$file1
if(is.null(data))
return(NULL)
df <- data$datapath %>%
filter(DQ.File == "In Compliance" | DQ.File == "Out of Compliance") %>%
group_by(DQ.File) %>%
summarise (n = n()) %>%
mutate(DQ.File = recode(DQ.File,
"In Compliance" = "Drivers In Compliance",
"Out of Compliance" = "Drivers Out Of Compliance"),
freq = round((n / sum(n)) * 100, 2),
label = paste(DQ.File, "-", paste(freq, "%", sep = ""))) %>%
select(-c(n, DQ.File))
output$plots = renderPlot({
df %>% ggplot(aes(x = 1, y = freq, fill = label)) +
coord_polar(theta = 'y') +
geom_bar(stat = "identity", color = 'black') +
scale_fill_manual(values = c("darkgreen", "red")) +
theme_minimal()+
theme(
axis.title.x = element_blank(),
axis.text = element_blank(),
axis.title.y = element_blank(),
panel.border = element_blank(),
panel.grid = element_blank(),
axis.ticks = element_blank(),
plot.title = element_text(size=14, face="bold"),
legend.title = element_blank(),
axis.text.x = element_blank(),
legend.background = element_rect(linetype = "solid"))
})
})
}
shinyApp(ui, server)
有没有办法在上传步骤中保留这些因素,还是我的问题在其他地方?
【问题讨论】: