简体   繁体   中英

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. 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. But i did reference the data to be read in the ui.R file.

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

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

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 . (And also make sure that the file exists in the working directory)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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