几天前,我在这里发布了一个错误消息(已经修复),但是我对创建R Shiny应用程序还很陌生,但我收到另一个我似乎无法弄清的错误消息。我正在制作一个分析动漫数据集的应用程序。
library(shiny)
library(tidyverse)
ui <- navbarPage(title = h1("Analysis of Anime", align = "center", img(src = "animeimg.jpg"),
height = 250, width = 250),
tabPanel("Genre",
titlePanel("Visualizing Genre"),
sidebarLayout(
sidebarPanel("Create plots of mean variables by genre.",
varSelectInput("var2", h5("Choose a variable to display."),
data = anime %>%
select(score, rank, popularity, members, favorites),
selected = "popularity"),
sliderInput("toprange", h5("Display Top"),
min = 5, max = 40, value = 5)),
mainPanel(plotOutput("bars")))
),
tabPanel("Studio",
titlePanel("Visualizing Studios"),
sidebarLayout("Create histograms of variables by studio.",
varSelectInput("var", h5("Choose a variable to display."),
data = anime %>% select(score, rank, popularity,
members, favorites),
selected = "popularity"),
mainPanel(plotOutput("hist"))
)
)
)
server <- function(input, output) {
output$bars <- renderPlot({
genre_plot(input$var2, input$toprange)
})
output$hist <- renderPlot({
studio_plot(input$var)
})
}
shinyApp(ui = ui, server = server)
以下是使用的绘图功能:
anime <- read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/
data/2019/2019-04-23/tidy_anime.csv")
genre_plot <- function(resp_variable, min) { #creates bar chart
anime %>%
group_by(genre) %>%
drop_na(!!sym(resp_variable)) %>%
summarize(avg = mean(!!sym(resp_variable))) %>%
head(min) %>%
ggplot(aes(x = reorder(genre, avg), y = avg)) +
geom_col(fill = "cornflowerblue", color = "black") +
labs(x = "Genre", y = paste("Mean", resp_variable)) +
ggtitle(paste("Mean", resp_variable, "by genre")) +
coord_flip()
}
studio_plot <- function(resp_variable) { #creates a histogram based on variable selected
anime %>%
group_by(studio) %>%
drop_na(!!sym(resp_variable)) %>%
ggplot(aes(x = !!sym(resp_variable))) +
geom_col(fill = "cornflowerblue") +
labs(x = resp_variable, y = "Frequency") +
ggtitle(paste("Frequency of", resp_variable))
}
尝试运行该应用程序后,我收到一条错误消息:“ match.arg(position)中的错误:'arg'必须为NULL或字符向量。”我不知道错误的出处或出处,所以如果有人可以帮助我弄清楚该错误,那就太好了!