[英]How can I structure this specific r-code to get a running shiny-app?
请注意,这是一个来自 Shinyapp 新手的问题。 我正在努力为我的考试练习,但我自己无法弄清楚这一点(我已经研究了很多,但在我看来这没有意义)
library(shiny)
library(ggplot2)
library(dplyr)
#Creating the title and an Output with the id "exampleOne"
ui <- fluidPage(
titlePanel("Titanic"),
plotOutput(outputId = "exampleOne")
)
server <- function(input, output) {
output$exampleOne <- renderPlot({
#opening my dataset of the titanic, mutating the data for the next step
titanic <- read.csv("titanic_data.csv",header = TRUE, sep=",")
newdata <- mutate(titanic, Status = ifelse (Survived > 0,
'Survived',
'Dead'))
#Trying to create a graph, that shows how many people survived/died separated by sex
ggplot( newdata,
aes(x = Sex, fill = Status))
+ geom_bar(position = "fill")
labs(y= "Proportion")
})
}
shinyApp(ui = ui, server = server)
正如我已经说过的,我是一个完全的初学者,完全迷路了。 R 和 Shiny 不是我的事我仍然希望有人能帮助我实现这一目标。
这很简单:虽然我花了一些努力才找到:
您在最后一行 ggplot() 中错过了+
:这是 train.csv 数据集的示例
library(shiny)
library(ggplot2)
library(dplyr)
#Creating the title and an Output with the id "exampleOne"
ui <- fluidPage(
titlePanel("Titanic"),
plotOutput(outputId = "exampleOne")
)
server <- function(input, output) {
output$exampleOne <- renderPlot({
titanic <- read.csv("train.csv",header = TRUE, sep=",")
newdata <- mutate(titanic, Status = ifelse (Survived > 0,
'Survived',
'Dead'))
ggplot( newdata,
aes(x = Sex, fill = Status)) +
geom_bar(position = "fill")+ ### THIS + IS MISSING
labs(y= "Proportion")
})
}
shinyApp(ui = ui, server = server)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.