I try to run machine learning technique by selecting web view. R gives error in select input: "SelectInput function is not found". I dont understant where exactly i made mistake. Probably it is really basic however, i dont have enough experience in shiny Could you possibly help me?
library(shiny)
library(plyr)
library(mfx)
library(plotly)
library(ggplot2)
library(dplyr)
Define UI for application that draws a barplot via plotly
ui <- shinyUI(pageWithSidebar(
headerPanel = ("Customer Risk Distribution"),
sidebarPanel(
SelectInput("select1", "1.Ürün", choices=c("a1"="a1","a2"="a2",
"a3"="a3","a4"="a4","a5"="a5")),
br(),
SelectInput("select2","İlçe", choices=c("B1"="B1", "B2"="B2","B3"="B3"))),
mainPanel(
tabPanel("Summary", textOutput("textDisplay")),
tabPanel("p",output$plotly()))
))
Define server logic required to draw a barplot
server <- function(input, output) {
##Pre-Data manipulation
Book<-Book1%>%
filter( AlarmSayisi<= 100,
TeknikDestekTalebi<= 15,
MobilDataKullanimi<=30)
Book$MobilDataKullanimi <- ifelse(Book$MobilDataKullanimi>1,1,0)
Book$HizmetSuresi <- Book$HizmetSuresi/12
Book$HizmetSuresi3<-ifelse(Book$HizmetSuresi<=3,1,0)
Book$SikayetSayisi[Book$SikayetSayisi >=1] <-1
Book$TeknikDestekTalebi<-ifelse(Book$TeknikDestekTalebi>1,1,0)
Book$IndirimOrani<-as.numeric(Book$IndirimOrani)
Book$IndirimOrani<-Book$IndirimOrani*100
Book$IndirimOrani[Book$IndirimOrani>0]<-1
Book$IndirimOrani[is.na(Book$IndirimOrani)]=0
Book$CHURN<-recode(Book$CHURN,"VAR"=1, "YOK"=0)
##REACTIVE FUNCTION FOR ML-PROBIT REG
output$select1<-renderUI({
selectInput("select1","Ürün",choices =c("a1"="a1","a2"="a2","a3"="a3","a4"="a4",
"a5"="a5","a6"="a6","a7"="a7","a8"="a8","a9"="a9","a10"="a10")) })
output$select2<-renderUI({
selectInput("select2", "İlçe",choices=c("B1"="B1",
"B2"="B2","B3"="B3"))})
data<-reactive({
a<-Book %>% filter(Urun==(input$select1) & Ilce==(input$select2))
attach(a)
res<-probitmfx(formula=CHURN~ HizmetSuresi3+SikayetSayisi+TeknikDestekTalebi+MobilDataKullanimi+IndirimOrani
,data = a,
atmean = TRUE, robust = FALSE, clustervar1 = NULL,
clustervar2 = NULL, start = NULL, control = list())
res1<-as.data.frame(res$mfxest)
pi<-select(res1,`dF/dx`,`P>|z|`)
if (pi[1,2] < 0.05) a$HizmetSuresi3 <- a$HizmetSuresi3*pi[1,1]
if (pi[2,2] < 0.05) a$SikayetSayisi <- a$SikayetSayisi*pi[2,1]
if (pi[3,2] < 0.05) a$TeknikDestekTalebi <- a$TeknikDestekTalebi*pi[3,1]
if (pi[4,2] < 0.05) a$MobilDataKullanimi <- a$MobilDataKullanimi*pi[4,1]
if (pi[5,2] < 0.05) a$IndirimOrani <- a$IndirimOrani*pi[5,1]
a$churn.prob<-a$HizmetSuresi3+a$SikayetSayisi+a$TeknikDestekTalebi+a$MobilDataKullanimi+a$IndirimOrani
aa<-select(a,c(SUBSCRIPTION_ID,churn.prob,CHURN))
aa
aaa <-aa %>% mutate("Risk_level"=
ifelse(between(churn.prob, -1.10,-0.60), "Very Low Risk",
ifelse(between(churn.prob, -0.601,-0.20), "Low Risk",
ifelse(between(churn.prob, -0.201,-0.01), "Medium Risk",
ifelse(between(churn.prob, 0,0.20), "High Risk",
ifelse(between(churn.prob, 0.201,0.60), "Highest Risk", "NON"))))))
aaa.churnvar<-aaa %>% filter(CHURN==1)
aaa.churnyok<-aaa %>% filter(CHURN==0)
adat.var<-count(aaa.churnvar,Risk_level)
adat.yok<-count(aaa.churnyok,Risk_level)
adat.yok$n2<-adat.yok$n
adat1<-left_join(adat.var, adat.yok, by = c("Risk_level"))
adat1
})
library(forcats) ##ggplotly for result
library(ggplot2)
library(plotly)
output$plotly<-renderPlotly({
p <- plot_ly(adat1, x = ~Risk_level, y = ~n.x, type = 'bar', name = 'Churn Var') %>%
add_trace(y = ~n2, name = 'Churn Yok') %>%
layout(xaxis = list(title = "",
categoryorder = "array",
categoryarray = c("Very Low Risk","Low Risk",
"Medium Risk","High Risk","Highest Risk"),barmode = 'group'),yaxis = list(title = ""))
p %>% config(displayModeBar = F)
})
output$textDisplay<- renderText({
paste(output$select1, "ve",output$select2)
})
}
shinyApp(ui = ui, server = server)