okay, and i can't make the prediction on shinny because Error in $: object of type 'closure' is not subsettable
this is my reprex
``` r
#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#
library(plotly)
#> Loading required package: ggplot2
#>
#> Attaching package: 'plotly'
#> The following object is masked from 'package:ggplot2':
#>
#> last_plot
#> The following object is masked from 'package:stats':
#>
#> filter
#> The following object is masked from 'package:graphics':
#>
#> layout
library(rsconnect)
library(caret)
#> Loading required package: lattice
library(lubridate)
#>
#> Attaching package: 'lubridate'
#> The following objects are masked from 'package:base':
#>
#> date, intersect, setdiff, union
library(GGally)
#> Registered S3 method overwritten by 'GGally':
#> method from
#> +.gg ggplot2
library(yardstick)
#> For binary classification, the first factor level is assumed to be the event.
#> Use the argument `event_level = "second"` to alter this as needed.
#>
#> Attaching package: 'yardstick'
#> The following objects are masked from 'package:caret':
#>
#> precision, recall, sensitivity, specificity
library(ggplot2)
library(hrbrthemes)
#> NOTE: Either Arial Narrow or Roboto Condensed fonts are required to use these themes.
#> Please use hrbrthemes::import_roboto_condensed() to install Roboto Condensed and
#> if Arial Narrow is not on your system, please see https://bit.ly/arialnarrow
library(viridis)
#> Loading required package: viridisLite
library(scales)
#>
#> Attaching package: 'scales'
#> The following object is masked from 'package:viridis':
#>
#> viridis_pal
library(shinydashboard)
#>
#> Attaching package: 'shinydashboard'
#> The following object is masked from 'package:graphics':
#>
#> box
library(shinythemes)
library(tibble)
library(partykit)
#> Loading required package: grid
#> Loading required package: libcoin
#> Loading required package: mvtnorm
library(psych)
#>
#> Attaching package: 'psych'
#> The following objects are masked from 'package:scales':
#>
#> alpha, rescale
#> The following objects are masked from 'package:ggplot2':
#>
#> %+%, alpha
library(tidyverse)
library(shiny)
#>
#> Attaching package: 'shiny'
#> The following object is masked from 'package:rsconnect':
#>
#> serverInfo
library(dplyr)
library(rsample)
library(formattable)
#>
#> Attaching package: 'formattable'
#> The following objects are masked from 'package:scales':
#>
#> comma, percent, scientific
#> The following object is masked from 'package:plotly':
#>
#> style
library(ggridges)
library(glue)
library(randomForest)
#> randomForest 4.7-1.1
#> Type rfNews() to see new features/changes/bug fixes.
#>
#> Attaching package: 'randomForest'
#> The following object is masked from 'package:dplyr':
#>
#> combine
#> The following object is masked from 'package:psych':
#>
#> outlier
#> The following object is masked from 'package:ggplot2':
#>
#> margin
library(shinythemes)
library(cowplot)
#>
#> Attaching package: 'cowplot'
#> The following object is masked from 'package:lubridate':
#>
#> stamp
library(e1071)
#>
#> Attaching package: 'e1071'
#> The following object is masked from 'package:rsample':
#>
#> permutations
# GLOBAL
# Model Dataset
## Load the dataset for model
# For Listening hour
forest_viz_ggplot <- readRDS("forest_viz_ggplot.RDS")
#> Warning in gzfile(file, "rb"): cannot open compressed file
#> 'forest_viz_ggplot.RDS', probable reason 'No such file or directory'
#> Error in gzfile(file, "rb"): cannot open the connection
# For Registration line plot
wsdm_for_registration <- readRDS("wsdm_for_registration.RDS")
#> Warning in gzfile(file, "rb"): cannot open compressed file
#> 'wsdm_for_registration.RDS', probable reason 'No such file or directory'
#> Error in gzfile(file, "rb"): cannot open the connection
# For auto renew and loyalty
forest_viz <- readRDS("forest_viz.RDS")
#> Warning in gzfile(file, "rb"): cannot open compressed file 'forest_viz.RDS',
#> probable reason 'No such file or directory'
#> Error in gzfile(file, "rb"): cannot open the connection
# For Model
forest_model_lr <-readRDS("forest_model_lr.RDS")
#> Warning in gzfile(file, "rb"): cannot open compressed file
#> 'forest_model_lr.RDS', probable reason 'No such file or directory'
#> Error in gzfile(file, "rb"): cannot open the connection
wsdm_for_registration_app <-wsdm_for_registration %>%
head(14) %>%
select(-tooltip)
#> Error in head(., 14): object 'wsdm_for_registration' not found
forest_viz_auto_renew<- forest_viz %>%
select(is_auto_renew,is_churn) %>%
group_by(is_auto_renew,is_churn) %>%
count() %>%
spread(is_churn,n) %>%
ungroup %>%
drop_na()
#> Error in select(., is_auto_renew, is_churn): object 'forest_viz' not found
forest_viz_auto_renew$is_auto_renew <-ifelse(forest_viz_auto_renew$is_auto_renew==1,"has auto renew feature","doesn't have auto renew feature")
#> Error in ifelse(forest_viz_auto_renew$is_auto_renew == 1, "has auto renew feature", : object 'forest_viz_auto_renew' not found
forest_viz_auto_renew$is_auto_renew <- as.factor(forest_viz_auto_renew$is_auto_renew)
#> Error in is.factor(x): object 'forest_viz_auto_renew' not found
forest_viz_auto_renew <- forest_viz_auto_renew %>%
pivot_longer(-is_auto_renew,names_to = "condition",names_transform = list(condition =as.factor))
#> Error in pivot_longer(., -is_auto_renew, names_to = "condition", names_transform = list(condition = as.factor)): object 'forest_viz_auto_renew' not found
forest_viz_auto_renew <- forest_viz_auto_renew %>%
mutate(`has auto renew feature?` = is_auto_renew,
`churn or not` = condition,
`number of subscriber` = value)
#> Error in mutate(., `has auto renew feature?` = is_auto_renew, `churn or not` = condition, : object 'forest_viz_auto_renew' not found
forest_viz_auto_renew_plot <- forest_viz_auto_renew %>%
select(-is_auto_renew,-condition,-value)
#> Error in select(., -is_auto_renew, -condition, -value): object 'forest_viz_auto_renew' not found
forest_viz_loyality <-forest_viz %>%
select(loyality_range,is_churn) %>%
group_by(loyality_range,is_churn) %>%
count() %>%
spread(is_churn,n) %>%
ungroup %>%
drop_na()
#> Error in select(., loyality_range, is_churn): object 'forest_viz' not found
forest_viz_plot_lh <- forest_viz %>%
select(listening_hour,is_churn) %>%
group_by(listening_hour,is_churn) %>%
count() %>%
spread(is_churn,n) %>%
ungroup %>%
drop_na()
#> Error in select(., listening_hour, is_churn): object 'forest_viz' not found
forest_viz_ggplot <-forest_viz_plot_lh
#> Error in eval(expr, envir, enclos): object 'forest_viz_plot_lh' not found
forest_viz_ggplot <- forest_viz_ggplot %>%
pivot_longer(-listening_hour,names_to = "condition",names_transform = list(condition =as.factor))
#> Error in pivot_longer(., -listening_hour, names_to = "condition", names_transform = list(condition = as.factor)): object 'forest_viz_ggplot' not found
# Random Forest Model
forest_model_lr <-readRDS("forest_model_lr.RDS")
#> Warning in gzfile(file, "rb"): cannot open compressed file
#> 'forest_model_lr.RDS', probable reason 'No such file or directory'
#> Error in gzfile(file, "rb"): cannot open the connection
forest_train_lr <-readRDS("forest_train_lr.RDS")
#> Warning in gzfile(file, "rb"): cannot open compressed file
#> 'forest_train_lr.RDS', probable reason 'No such file or directory'
#> Error in gzfile(file, "rb"): cannot open the connection
# Random Forest test dataframe
forest_test_lr <- readRDS('forest_test_lr.RDS')
#> Warning in gzfile(file, "rb"): cannot open compressed file 'forest_test_lr.RDS',
#> probable reason 'No such file or directory'
#> Error in gzfile(file, "rb"): cannot open the connection
# test dataset wrangling
forest_test_lr$is_auto_renew <-ifelse(forest_test_lr$is_auto_renew==1,"yes","no")
#> Error in ifelse(forest_test_lr$is_auto_renew == 1, "yes", "no"): object 'forest_test_lr' not found
forest_test_lr$is_auto_renew <- as.factor(forest_test_lr$is_auto_renew)
#> Error in is.factor(x): object 'forest_test_lr' not found
forest_test_lr$unq_track <- round(forest_test_lr$unq_track,0)
#> Error in eval(expr, envir, enclos): object 'forest_test_lr' not found
forest_test_lr$unq_track <- round(forest_test_lr$unq_track,0)
#> Error in eval(expr, envir, enclos): object 'forest_test_lr' not found
forest_test_lr$num_100_perday <- round(forest_test_lr$num_100_perday,0)
#> Error in eval(expr, envir, enclos): object 'forest_test_lr' not found
# Define UI for application that draws a histogram
ui <- navbarPage(h3("KKBOX Online Music Streaming Churn Dashboard"),
theme = shinytheme("sandstone"),
tabPanel(title=h3("| Home"),
fluidRow(box(width=12,solidHeader = TRUE, align = "center",
imageOutput("home_img",height = "320px"))),
br(),
br(),
br(),
br(),
br(),
br(),
br(),
br(),
br(),
br(),
br(),
br(),
br(),
br(),
fluidRow(box(width=12,solidHeader = TRUE, align = "center",
br(),
br(),
br(),
br(),
br(),
br(),
h4(strong("Project Description")),
p(style="text-align: justify; font-size = 25px",
"This Project is developed to make prediction about churn in Online Music Streaming KKBOX.
The Prediction is made withRandom Forest Model and can describe about factor that affecting churn rate in Online Music
Streaming"),
tags$blockquote("For any service company that bills on a recurring basis, a key variable is the rate of churn. Harvard Business Review, March 2016"),
hr())
)),
tabPanel(title=h3("| EDA"),
fluidRow(box(width = 12,
h1("Explanatory Data Analysis"))),
fluidRow( box(width = 6, solidHeader = TRUE,
plotlyOutput(outputId = "listen_plot")),
box(width= 6, solidHeader = TRUE,
plotOutput("growth_plot")
)
),
br(),
br(),
br(),
fluidRow(box(width = 6, solidHeader = TRUE,
plotlyOutput(outputId = "loyality_plot")),
box(width= 6, solidHeader = TRUE,
plotlyOutput("renew_plot"))
) # tabpanel Second tap EDA
),
tabPanel(title=h3("| Churn Prediction"),
sidebarPanel(fluidRow(box(width = 6,
h1("Variable input"))),
fluidRow(box(width = 6,
selectInput(inputId = "automaticsubscription",
label = "Has auto subscription feature?",
choices = levels(forest_test_lr$is_auto_renew)),
selectInput(inputId = "pricerange",
label = "How much does the subscriber pay?",
choices =levels(forest_test_lr$price_range)),
sliderInput(inputId = "slidelisten",
label = "The Duration of listening hour",
min = min(forest_test_lr$listening_hour),
max = max(forest_test_lr$listening_hour),
value = min(forest_test_lr$listening_hour),
step = 200)),
box(width = 6,
selectInput(inputId = "loyalinput",
label = "How loyal are the subscriber",
choices =levels(forest_test_lr$loyality_range)) ,
sliderInput(inputId = "slideuniquetrack",
label = "Number of listened song each day",
min = min(forest_test_lr$unq_track),
max = max(forest_test_lr$unq_track),
value = min(forest_test_lr$unq_track),
step = 5),
sliderInput(inputId = "slide100",
label = "Number of listened song at full duration",
min = min(forest_test_lr$num_100_perday),
max = max(forest_test_lr$num_100_perday),
value = min(forest_test_lr$num_100_perday),
step = 5),
actionButton("go", "Predict!",icon("paper-plane"),
style="color: #fff; background-color: #337ab7; border-color: #2e6da4")
)
)
),
mainPanel(
tags$label(h3('The predicted churn probability')),
br(),
textOutput("pred"),
br(),
plotlyOutput('Varimp'))),
tabPanel(title=h3("| Data"),
DT::dataTableOutput("tabelchurn")
),
tabPanel(title=h3("| About"),
h2("About Me"),
fluidRow(box(width=5,
img(src="about linkedin.png", width="40", height="40"),
h2(a(href="https://www.linkedin.com/in/adhiperdanaputra/", "Adhi Perdana Putra")))))
)
#> Error in levels(forest_test_lr$is_auto_renew): object 'forest_test_lr' not found
# Define server logic required to draw a histogram
server <- function(input, output) {
forest_model_lr <-readRDS("forest_model_lr.RDS")
input_df <- reactive({
data.frame(
plan_list_price = max(forest_test_lr$plan_list_price),
actual_amount_paid = max(forest_test_lr$actual_amount_paid),
is_auto_renew = as.factor(input$automaticsubscription),
year_registration = max(forest_test_lr$year_registration),
sum_num_25 =mean(forest_test_lr$sum_num_25),
sum_num_50 = mean(forest_test_lr$sum_num_50),
sum_num_75 = mean(forest_test_lr$sum_num_75),
sum_num_985 = mean(forest_test_lr$sum_num_985),
sum_num_100 = mean(forest_test_lr$sum_num_100),
num_unq_sum = mean(forest_test_lr$num_unq_sum),
plan_list_price_mean = mean(forest_test_lr$plan_list_price_mean),
actual_amount_paid_mean = mean(forest_test_lr$actual_amount_paid),
avg_time_perday= mean(forest_test_lr$avg_time_perday),
unq_track = input$slideuniquetrack,
num_25_perday = mean(forest_test_lr$num_25_perday),
num_50_perday = mean(forest_test_lr$num_50_perday),
num_75_perday = mean(forest_test_lr$num_75_perday),
num_985_perday = mean(forest_test_lr$num_985_perday),
num_100_perday = as.numeric(input$slide100),
loyality_range = as.factor(input$loyalinput),
price_day = mean(forest_test_lr$price_day),
price_range = as.factor(input$pricerange),
listening_hour = as.numeric(input$slidelisten))
input_df$is_auto_renew <- factor(input_df$is_auto_renew, levels = c("yes", "no"))
input_df$loyality_range <- factor(input_df$loyality_range, levels = c("0","1","2","3","4","5","6","7","8","9","10","11","12","13"))
input_df$price_range <- factor(input_df$price_range, levels = c("0-129","129-133","133-180"))
})
pred <- reactive({
predict(forest_model_lr , input_df(), type = "response")
})
output$pred <- renderText({pred()})
output$tabelchurn <- DT::renderDataTable({
DT::datatable(forest_train_lr,options = list(scrollX=TRUE))
})
}
# Run the application
shinyApp(ui = ui, server = server)
#> Error in force(ui): object 'ui' not found
Created on 2022-12-26 with reprex v2.0.2
thank you for the help :pray: :pray: :pray: :pray: :pray: