Hey, I have been working on an error for a few days now, my shiny app loads as 'Not Found' intermittently, as in sometimes it will load and other times it will not.
I receive the error:
Loading required package: shiny
Warning: package 'shiny' was built under R version 3.5.2
Listening on http://127.0.0.1:7037
I have suspicions it is because the file is not running from the correct directory, as I am loading it from the Desktop outside of the R folder. Is there a specific folder the files should be contained in? A working example is below.
Task2.Rmd
---
title: "Hello"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
social: ["menu"]
runtime: shiny
#options: (shiny.maxRequestSize = 1500*1024^2)
---
```{r setup, include=FALSE}
suppressPackageStartupMessages({
library(shiny)
library(flexdashboard)
library(datasets)
library(caTools)
library(hydroGOF)
})
```
Column {.tabset}
-------------------------------------
### Linear Regression Model
```{r}
ui <- fluidPage(
titlePanel("Upload Transaction Data Set"),
sidebarLayout(
sidebarPanel(
fileInput("file1", "Choose CSV File",
multiple = FALSE,
accept = c("text/csv",
"text/comma-separated-values,text/plain",
".csv")),
p("The transaction data file must contain a 'Class' column that specifies the number 1 for fraudulent transactions, and 0 otherwise"),
p("The 'Actual' graph exhibits the real calculations of the uploaded data, and the 'predicted' graph exhibits the predicted 'Class' column based on the other features of data included in your upload.")
),
mainPanel(
h1("Models"),
plotOutput("actual"),
plotOutput("prediction"),
h1("Root Mean Square Error (RMSE) Accuracy %"),
verbatimTextOutput("accuracy"),
h1("Summary"),
verbatimTextOutput("summary")
)
)
)
server = function(input,output){
options(shiny.maxRequestSize=500*1024^2)
thedata = reactive({
req(input$file1)
read.csv(file = input$file1$datapath)
})
output$prediction = renderPlot({
req(thedata())
set.seed(2)
#Split data
split <- sample.split(thedata(), SplitRatio=0.7)
thedata <- subset(thedata(), split=TRUE)
actual <- subset(thedata(), split=FALSE)
#Create the model
model <- lm(Class ~.,data = thedata())
#Prediction
prediction <- predict(model, actual)
distPred <- predict(model, actual)
#Comparing predicted vs actual model
plot(prediction,type = "l",lty= 1.8,col = "blue")
lines(prediction, type = "l", col = "blue")
})
output$actual = renderPlot({
req(thedata())
set.seed(2)
split <- sample.split(thedata()$Class,0.7)
thedata <- subset(thedata(),split)
actual <- subset(thedata(),!split)
model <- lm(Class ~.,data = thedata())
prediction <- predict(model, actual)
plot(actual$Class,type = "l",lty= 1.8,col = "blue")
output$accuracy <- renderPrint({
rmse <- sqrt(mean(prediction-thedata$Class)^2)/diff(range(thedata$Class))
rmse
})
})
output$summary <- renderPrint({
model <- lm(Class ~.,data = thedata())
summary (model)
})
}
shinyApp(ui, server)
```
-------------------------------------
### Logistic Regression Model
```{r}
ui <- fluidPage(
titlePanel("Upload Transaction Data Set"),
sidebarLayout(
sidebarPanel(
fileInput("file1", "Choose CSV File",
multiple = FALSE,
accept = c("text/csv",
"text/comma-separated-values,text/plain",
".csv")),
p("The transaction data file must contain a 'Class' column that specifies the number 1 for fraudulent transactions, and 0 otherwise"),
p("The 'Actual' graph exhibits the real calculations of the uploaded data, and the 'predicted' graph exhibits the predicted 'Class' column based on the other features of data included in your upload.")
),
mainPanel(
h1("Models"),
plotOutput("actual"),
plotOutput("prediction"),
h1("Confusion Matrix"),
verbatimTextOutput("confMatrix"),
h1("Accuracy (%)"),
verbatimTextOutput("accuracy"),
h1("Summary"),
verbatimTextOutput("summary")
)
)
)
server = function(input,output){
options(shiny.maxRequestSize=500*1024^2) #Max File Size
thedata = reactive({
req(input$file1)
read.csv(file = input$file1$datapath)
})
output$prediction = renderPlot({
req(thedata())
#Split Data
split <- sample.split(thedata(), SplitRatio=0.7)
train <- subset(thedata(), split=TRUE)
Actual <- subset(thedata(), split=FALSE)
#Create Model
mymodel <- glm(Class ~., data = thedata(), family = binomial, control = list(maxit = 50))
#Prediction
Prediction <- predict(mymodel, Actual, type="response")
#Predicted Model
plot(Prediction,type = "l",lty= 1.8,col = "blue")
})
output$actual = renderPlot({
req(thedata())
# Split Data
split <- sample.split(thedata(), SplitRatio=0.7)
train <- subset(thedata(), split=TRUE)
Actual <- subset(thedata(), split=FALSE)
#Create Model
mymodel <- glm(Class ~., data = thedata(), family = binomial, control = list(maxit = 50))
#Prediction
Prediction <- predict(mymodel, Actual, type="response")
#Actual Model
plot(Actual$Class,type = "l",lty= 1.8,col = "blue")
output$confMatrix <- renderPrint({
confusionMatrix <- table(Actual_Value=train$Class, Predicted_Values=Prediction > 0.5)
confusionMatrix
})
output$accuracy <- renderPrint({
confusionMatrix <- table(Actual_Value=train$Class, Predicted_Values=Prediction > 0.5)
(confusionMatrix[[1,1]] + confusionMatrix[[2,2]]) / sum(confusionMatrix) *100
})
})
output$summary <- renderPrint({
mymodel <- glm(Class ~., data = thedata(), family = binomial, control = list(maxit = 50))
summary (mymodel)
})
}
shinyApp(ui, server)
```