Can't Deploy machine learning model

Hello, i'm new to R and attempt to deploy random forest model but my dataframe that used to calculate, doesn't show, below is my github :

and the error is Warning: Error in renderText: object 'rfpred' not found
97: renderText [/Users/adhiperdanaputra/Documents/DCD Desember/DCD 17 Final/projectfinal/app.R#456]
96: func
83: renderFunc
82: output$prediction
1: runApp
thank you for your help :pray: :pray:

Here is a minimal example of your problem

library(shiny)

ui <- fluidPage(
  verbatimTextOutput("prediction"),
  verbatimTextOutput("gotext"),
  actionButton("go","go")
)

server <- function(input, output, session) {
  output$gotext <- renderText ({input$go})
  
  output$prediction <- renderText({
    if(input$go >0) {
      rfpred <- "some text" 
      }
      rfpred[1]
})}

shinyApp(ui, server)

the simplest solution is to move the closing curly brace around the go>0 if clause to contain everything in the renderText rather than rfpred creation only.

1 Like

thank you!!, but i have some issue when deploy my model :

"Text to be written must be a length-one character vector"

Here is my github :

thanks a lot!!

I don't have the capacity to debug your whole app for you but a couple of things
turn on shiny::devmode() to improve the error logging; often it will point you to the code line with the problem.
Theres also the shiny debug guide you should look at .

thank you, this is my code :pray:

 ui = navbarPage(h3("KKBOX Online Music Streaming Churn Dashboard"),
                  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 =   (forest_test_lr$is_auto_renew)),
                                                     selectInput(inputId = "pricerange",
                                                                 label = "How much does the subscriber pay?",
                                                                 choices =   (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,
                                                     sliderInput(inputId = "slideloyal",
                                                                 label = "How loyal are the subscriber?",
                                                                 min = min(forest_test_lr$loyality_range),
                                                                 max = max(forest_test_lr$loyality_range),
                                                                 value = min(forest_test_lr$loyality_range),
                                                                 step = 3),
                                                     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(
                             fluidRow( box(width = 6,
                                           infoBoxOutput("prediction")),
                                       box(width = 6,
                                           infoBoxOutput("class"))))))
  server = function(input, output, session) {
    output$prediction <- renderInfoBox({
      
      if(input$go >0) {
        rfpred <- predict(forest_model_lr ,
                          prd_df = 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$slideloyal),
                            price_day =  mean(forest_test_lr$price_day),
                            price_range = as.factor(input$pricerange),
                            listening_hour = as.numeric(input$slidelisten)                 
                          ),
                          type = "prob") }
      rfpreddf <- as.data.frame(rfpred)
      
      infoBox(
        "Probability Churn", paste0(rfpreddf$churn_prob, "%"), icon = icon("list"),
        color = "blue", fill = TRUE
      )})
  }
)

below this is data frame
stay_prob churn_prob
120389 1 0
100793 1 0
216050 0 1
22056 1 0
183280 1 0
189234 1 0


thank you for your help :pray:

You probably need to collapse this

thank you, but how i can show the probability of churn?

I recommend looking at the documentation for paste0

?paste0

and learning about the collapse feature

hello, i'm new to shinny and can't deploy random forest model because Error in $<-.data.frame: replacement has 0 rows, data has 1

below is my code :pray:

ui <- 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('Churn Probability')),
                verbatimTextOutput('Contents'),
              br(),
              infoBoxOutput("predchurn"),
              plotlyOutput('Varimp'))),

server <- function(input, output) {

forest_model_lr <-readRDS("forest_model_lr.RDS")

output$predchurn <- renderInfoBox({
go <- input$go
topredchurn <- 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))
print(topredchurn )
print(str(topredchurn ))
topredchurn$is_auto_renew <- factor(topredchurn$is_auto_renew , levels = c("yes", "no"))
topredchurn$loyality_range <- factor(topredchurn$loyality_range , levels = c(0, 1, 2,3,4,5,6,7,8,9,10,11,12,13))
topredchurn$pricerange <- factor(topredchurn$pricerange , levels = c("0-129", "129-133", "133-180"))


rfprob <- predict( forest_model_lr, topredchurn, type = "prob")
print(rfprob)

})

thank you

i have change type data into the factor

You have not given a reprex so you cant expect much support. I do see lots of naked use of input$whatever without protection via req() or some other mechanism. I expect this contributes to your problems.

hallo, i'm just make data frame with reactive values, but I found error : error in as.data.frame.default: cannot coerce class ‘"reactivevalues"’ to a data.frame

below is my reprex

http://localhost:13729/session/extra-bass_reprex_preview.html

any idea to solve the error? thank you

For your error i would you you forgot to use brackets () to get the reactive values content.

Also, your link, is just a broken link. Normally a reprex would be some formatted code on a post anyway, so no need to try to link.

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:

Looks like you have confusion in what you are attempting because you are trying to make an object out of parts of itself.

so i attempts to change the type data into factor since I get the error message "New factor levels not present in the training data". any recommendation what should I change?

You have a problem that you make nameless df and then try to alter it, and you do it with reference to the name of the reactive in which you are working; proceed like this if you need to alter the data.frame...

input_df <- reactive({
    
somename <-    data.frame(...


server <- function(input, output) {
  
  
  forest_model_lr <-readRDS("forest_model_lr.RDS")
  
  input_df <- reactive({
    
   churn_pred_df <- 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))
    
   churn_pred_df$is_auto_renew <- factor(churn_pred_df$is_auto_renew, levels = c("yes", "no"))
    churn_pred_df$loyality_range <- factor(churn_pred_df$loyality_range, levels = c("0","1","2","3","4","5","6","7","8","9","10","11","12","13"))
    churn_pred_df$price_range <- factor(churn_pred_df$price_range, levels = c("0-129","129-133","133-180"))
    
    
  })
  

i have name it but plan_list price is not found

so if i want to change into factor, change in the reactive function?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.