简体   繁体   English

R闪亮摘要统计信息和箱线图

[英]R Shiny Summary Statistics and Boxplot

I'm very new to R and i need some help on getting an output for summary statistics and boxplot from a csv file. 我对R很陌生,我需要一些帮助来获取csv文件的摘要统计信息和箱线图的输出。 I tried the following ui.R and server.R file but it had an error message of not being able to find the csv file for the output. 我尝试了以下ui.R和server.R文件,但它出现一条错误消息,即找不到输出的csv文件。 But i did reference the data to be read in the ui.R file. 但是我确实引用了ui.R文件中要读取的数据。

Appreciate any advice or help on this as i'm really lost at why the error is happening. 感谢任何建议或帮助,因为我真的迷失了为什么会发生错误。 Thanks. 谢谢。

data <-read.csv("sample_finaldata.csv", stringsAsFactors = FALSE)

ui.R ui.R

library(shiny)
library(ggplot2)
library(dplyr)

data <-read.csv("sample_finaldata.csv", stringsAsFactors = FALSE)

shinyUI(fluidPage(
  titlePanel("Anime Selection"),
  sidebarLayout(
  sidebarPanel(
      selectInput("var",label="Choose a variable",choice=c("user_days_spent_watching"=1,
                                                       "score"=2,
                                                       "age"=3,
                                                       "user_days"=4,
                                                       "stats_mean_score"=5,
                                                       "user_days"=6
                                                       ), selectize=FALSE)),
mainPanel(
  h2("Summary of the variable"),
  verbatimTextOutput("sum"),
  plotOutput("box")
    )
  ))
)

server.R server.R

library(shiny)
library(datasets)

shinyServer(function(input,output){

  output$sum <- renderPrint({

    summary(data[,as.numeric(input$var)])
  })

  output$box <- renderPlot({

x<-summary(data[,as.numeric(input$var)])
boxplot(x,col="sky blue",border="purple",main=names(data[as.numeric(input$var)]))
  })
}
)

You should put the data <-read.csv("sample_finaldata.csv", stringsAsFactors = FALSE) inside the server.R . 您应该将data <-read.csv("sample_finaldata.csv", stringsAsFactors = FALSE)放入server.R (And also make sure that the file exists in the working directory) (并确保该文件存在于工作目录中)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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