Reputation: 1
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)]))
})
}
)
Upvotes: 0
Views: 907
Reputation: 662
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)
Upvotes: 1