Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 84
1
library(shiny)
2
library(dplyr)
3
library(randomForest)
4
library(ggplot2)
5
6
data <- read.delim("data.csv",header=T,sep=',')
7
data <- subset(data,select=c('diagnosis','radius_worst','perimeter_worst','concave.points_worst','area_worst','concave.points_mean'))
8
data$Class<-data$diagnosis
9
data<-data[-1]
10
11
#train your model
12
model <- randomForest(
13
Class ~ .,
14
data=data,
15
importance=TRUE,
16
ntree=1000
17
)
18
19
20
ui <- fluidPage(
21
titlePanel("Cancer Classifier"),
22
sidebarLayout(
23
sidebarPanel("Input Features:",
24
br(),
25
numericInput("radius_worst_input","Radius Worst:",round(mean(data$radius_worst),2),min=0,max=Inf),
26
br(),
27
numericInput("perimeter_worst_input","Perimeter Worst",round(mean(data$perimeter_worst),2),min=0,max=Inf),
28
br(),
29
numericInput("concave.points_worst_input","Concave Points Worst",round(mean(data$concave.points_worst),2),min=0,max=Inf),
30
br(),
31
numericInput("area_worst_input","Area Worst",round(mean(data$area_worst),2),min=0,max=Inf),
32
br(),
33
numericInput("concave.points_mean_input","Concave Points Mean",round(mean(data$concave.points_worst),2),min=0,max=Inf)
34
),
35
mainPanel("Results:",
36
htmlOutput("results"),
37
br(),
38
br(),
39
plotOutput("coolplot"))
40
)
41
)
42
43
server <- function(input, output) {
44
45
output$coolplot <- renderPlot({
46
plot<- ggplot(data, aes(radius_worst))+ geom_histogram()
47
plot + geom_vline(xintercept=input$radius_worst_input, linetype="dashed", color = "red")
48
})
49
50
output$results <- renderText({
51
52
test <- data.frame(radius_worst=input$radius_worst_input,perimeter_worst=input$perimeter_worst_input,concave.points_worst=input$concave.points_worst_input,area_worst=input$area_worst_input,concave.points_mean=input$concave.points_mean_input)
53
pred<-predict(model,test)
54
if(pred=="M"){
55
text<-paste("<font color=\"#FF0000\"><font size=\"1000\">","Malignant", "</font>")
56
}else{
57
text<-paste("<font color=\"#008000\"><font size=\"1000\">","Benign", "</font>")
58
}
59
text
60
})
61
}
62
shinyApp(ui = ui, server = server)
63
64
65
66