r - R Shiny“错误:要写入的文本必须是长度为一的字符向量”
问题描述
我正在尝试帮助朋友调试他们对基本闪亮应用程序的第一次尝试。我知道有些事情对这段代码并不理想(至少拼写),但我不明白为什么它应该抛出主题错误......
ui.R 是
library(magrittr)
library(dplyr)
library(tidyr)
olympic <- read.csv("olympic_games.csv", header = TRUE)
shinyServer(fluidPage(
titlePanel("Olympic games medals from 2002 - 2012"),
country <- levels(olympic$Country),
total_medal <- unique(olympic$Total.Medal),
sidebarLayout(
sidebarPanel(
helpText("Choose the contry to know how many medals they have"),
selectInput("Country",
label = "chose country",
choices = country,
selected = country[1]),
selectInput("country1",
label = "chose country",
choices = country,
selected=country[2]),
br(),
radioButtons("color", "Select the colour of histogram if you like?",
choices=c("green","red","yellow"), selected= "green")
),
mainPanel(
plotOutput("Olympic_games")
)
))
)
和 server.r
library(magrittr)
library(dplyr)
library(tidyr)
library(ggplot2)
shinyServer(
function(input,output,session){
olympic <- read.csv("olympic_games.csv", header = TRUE)
output$Olympic_games <- renderPlot({
olympic1 <- subset(olympic,Country==input$Country)
olympic2 <- subset(olympic,Country==input$country1)
col <- input$color
frames <- rbind(olympic1,olympic2)
ggplot(frames, aes(Total.Medals))+
geom_histogram(aes(Total.Medals,fill=Country),color=col) + facet_grid(Country~Total.Medals)
}
)
}
)
当读取 olympic_games.csv 文件时,数据看起来像
head(olympic)
Athlete Age Country Year Closing.Ceremony.Date Sport Gold.Medals Silver.Medals
1 Michael Phelps 23 United States 2008 8/24/2008 Swimming 8 0
2 Michael Phelps 19 United States 2004 8/29/2004 Swimming 6 0
3 Michael Phelps 27 United States 2012 8/12/2012 Swimming 4 2
4 Natalie Coughlin 25 United States 2008 8/24/2008 Swimming 1 2
5 Aleksey Nemov 24 Russia 2000 10/1/2000 Gymnastics 2 1
6 Alicia Coutts 24 Australia 2012 8/12/2012 Swimming 1 3
Bronze.Medals Total.Medals
1 0 8
2 2 8
3 0 6
4 3 6
5 3 6
6 1 5
当您尝试将两个字符串传递给一个只需要一个的闪亮的 UI 函数时,我发现了对这个错误的引用,但我在这里看不到任何可能发生这种情况的地方。
解决方案
推荐阅读
- php - 将 foreach 的值返回到表中
- java - 在骆驼中模拟端点响应
- email - Google Form 邮件通知脚本。电子邮件始终将“我”作为发件人
- php - 我可以将 node_modules 移动到公共文件夹中吗?
- symfony - 清漆恐慌 - 放弃日志(vsl)
- azure-traffic-manager - Azure 流量管理器可用性
- java - Java ProcessBuilder:curl:(1)libcurl中不支持或禁用协议“'https”
- javascript - 如何以角度 4 捕获图像元数据
- php - 未指定phpcs版本
- excel - Visual Basic Datagridview到带有主键的mysql(按顺序自动生成的数字)