rajistics commited on
Commit
4330865
1 Parent(s): a514e02

first push

Browse files
Files changed (4) hide show
  1. Dockerfile +12 -0
  2. Rprofile.site +3 -0
  3. app/server.R +23 -0
  4. app/ui.R +13 -0
Dockerfile ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM rocker/r-ver
2
+
3
+ # basic shiny functionality
4
+ RUN R -q -e "install.packages(c('shiny', 'rmarkdown'))"
5
+
6
+ # copy the app to the image
7
+ WORKDIR /shinyapp
8
+ COPY --link Rprofile.site /usr/local/lib/R/etc/
9
+ COPY --link app /shinyapp/
10
+
11
+ EXPOSE 7860
12
+ CMD ["R", "-q", "-e", "shiny::runApp('/shinyapp')"]
Rprofile.site ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ local({
2
+ options(shiny.port = 7860, shiny.host = "0.0.0.0")
3
+ })
app/server.R ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function(input, output, session) {
2
+
3
+ # Combine the selected variables into a new data frame
4
+ selectedData <- reactive({
5
+ iris[, c(input$xcol, input$ycol)]
6
+ })
7
+
8
+ clusters <- reactive({
9
+ kmeans(selectedData(), input$clusters)
10
+ })
11
+
12
+ output$plot1 <- renderPlot({
13
+ palette(c("#E41A1C", "#377EB8", "#4DAF4A", "#984EA3",
14
+ "#FF7F00", "#FFFF33", "#A65628", "#F781BF", "#999999"))
15
+
16
+ par(mar = c(5.1, 4.1, 0, 1))
17
+ plot(selectedData(),
18
+ col = clusters()$cluster,
19
+ pch = 20, cex = 3)
20
+ points(clusters()$centers, pch = 4, cex = 4, lwd = 4)
21
+ })
22
+
23
+ }
app/ui.R ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ vars <- setdiff(names(iris), "Species")
2
+
3
+ pageWithSidebar(
4
+ headerPanel('Iris k-means clustering'),
5
+ sidebarPanel(
6
+ selectInput('xcol', 'X Variable', vars),
7
+ selectInput('ycol', 'Y Variable', vars, selected = vars[[2]]),
8
+ numericInput('clusters', 'Cluster count', 3, min = 1, max = 9)
9
+ ),
10
+ mainPanel(
11
+ plotOutput('plot1')
12
+ )
13
+ )