I am trying develop an application in RShiny. My Objective: An application which can do logistic regression and display the output.
Steps:
- User will upload the CSV(1st TAB)
- User select the independent variable(2nd TAB)
- User Select the other variables(2nd TAB)
- Mainpanel in 2nd TAB will display the Summary of logistic regression.
My Code:
library(shiny)
ui<-navbarPage("Model Developement by Subhasish",
tabPanel("Data Import",sidebarLayout(sidebarPanel( fileInput("file","Upload your CSV",multiple = FALSE),
tags$hr(),
h5(helpText("Select the read.table parameters below")),
checkboxInput(inputId = 'header', label = 'Header', value = FALSE),
checkboxInput(inputId = "stringAsFactors", "stringAsFactors", FALSE),
radioButtons(inputId = 'sep', label = 'Separator', choices = c(Comma=',',Semicolon=';',Tab='\t', Space=''), selected = ',')
),
mainPanel(uiOutput("tb1"))
) ),
tabPanel("Model_dev",sidebarLayout(sidebarPanel(uiOutput("model_select"),uiOutput("var1_select"),uiOutput("rest_var_select")),mainPanel( helpText("Your Selected variables"),verbatimTextOutput("other_val_show"))))
)
server<-function(input,output) { data <- reactive({
file1 <- input$file
if(is.null(file1)){return()}
read.table(file=file1$datapath, sep=input$sep, header = input$header, stringsAsFactors = input$stringAsFactors)
})
output$table <- renderTable({
if(is.null(data())){return ()}
data()
})
output$tb1 <- renderUI({
tableOutput("table")
})
output$model_select<-renderUI({
selectInput("modelselect","Select Algo",choices = c("Logistic_reg"="logreg","SVM"="svm"))
})
output$var1_select<-renderUI({
selectInput("ind_var_select","Select Independent Var", choices =as.list(names(data())),multiple = FALSE)
})
output$rest_var_select<-renderUI({
checkboxGroupInput("other_var_select","Select other Var",choices =as.list(names(data())))
})
output$other_val_show<-renderPrint({
input$other_var_select
#f<-data()
#library(caret)
#logreg<-glm(f[,1]~.,family = binomial,data=f)
#summary(logreg)
})
}
shinyApp(ui=ui,server=server)
Till now The CSV Upoload part is complete. Problem faced as glm() function req structure like: glm(var 1~ var 2+var 3+ var 4,family=binomial,data=df)
How can I use the checkbox values like var 2+ var 3..? I am using Shiny R from last 1 week. so there might be any easier solution which I am not able to discover.
Thanks in advance