[英]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.