简体   繁体   English

我怎样才能构建这个特定的 r 代码来获得一个正在运行的闪亮应用程序?

[英]How can I structure this specific r-code to get a running shiny-app?

Please mind that this is a question from a total Shinyapp beginner.请注意,这是一个来自 Shinyapp 新手的问题。 Im trying to practice for my exam and just can't figure this out my self (I've researched a lot but it just doesn't make sense in my mind)我正在努力为我的考试练习,但我自己无法弄清楚这一点(我已经研究了很多,但在我看来这没有意义)

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)

As I already said I'm a total beginner and totally lost.正如我已经说过的,我是一个完全的初学者,完全迷路了。 R and Shiny are kind of not my thing I still hope someone can help me to get this going. R 和 Shiny 不是我的事我仍然希望有人能帮助我实现这一目标。

It is very simple: Though it took me some efforts to find:这很简单:虽然我花了一些努力才找到:

You miss a + in the last but one ggplot() line: Here is an example with the train.csv dataset您在最后一行 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM