Last active
September 7, 2016 23:25
-
-
Save pahearn1/075ff9be9c63484b2177aca836bfe9ad to your computer and use it in GitHub Desktop.
Shiny code creating a dynamic classification tree based on user selected variables using the PIMA dataset and dplyr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| shinyApp( | |
| ui=(fluidPage( | |
| titlePanel(title=h4("Classification Tree",align="center")), | |
| sidebarLayout( | |
| sidebarPanel( | |
| selectInput("attributes2", | |
| label = "Attribute:", | |
| choices = c("preg"=2,"plas"=3,"press"=4,"skin"=5,"ins"=6,"mass"=7,"pedi"=8,"age"=9), | |
| selected = c(7,3), | |
| multiple = TRUE) | |
| ), | |
| mainPanel( | |
| plotOutput("treePlot") | |
| ) | |
| ) | |
| )), | |
| server=(function(input, output) { | |
| output$treePlot <- renderPlot({ | |
| dt_tree=data%>% | |
| select(as.numeric(input$attributes2)) | |
| dt_tree=dt_tree%>% | |
| mutate(data[,1]) | |
| names(dt_tree)[names(dt_tree)=="data[, 1]"]="class" | |
| tree1=rpart(class~., data=dt_tree,method = "class",parms=list(split="split")) | |
| rpart.plot(tree1) | |
| }) | |
| }), | |
| options=list(height=460) | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment