Introduction
soroban
’s kmsModule
generates k-means
cluster.
In this article, we’ll use USArrests
dataset of datasets,
which can be just use by data("USArrests")
This article is based on 0.0.1 Version of soroban
Declare module
soroban
’s module assumes that used in the Shiny application.
and You can use snippet(type shinyapp
) to build very
basic shiny application.
library(shiny)
ui <- fluidPage(
)
server <- function(input, output, session) {
}
shinyApp(ui, server)
This application will show nothing.
So let’s add treeModule
in ui.
ui <- fluidPage(
mod_kmsModule_ui(
id = 'module'
)
)
also, treeModule
in server.
server <- function(input, output, session) {
mod_kmsModule_server(
id = 'module',
inputData = reactive(datasets::USArrests)
)
}
So final (which is very basic) code will like this. (Assume data from
AER
loaded.)
library(shiny)
ui <- fluidPage(
mod_kmsModule_ui(
id = 'module'
)
)
server <- function(input, output, session) {
mod_kmsModule_server(
id = 'module',
inputData = reactive(datasets::USArrests)
)
}
shinyApp(ui, server) # Run application
You should notice 2 things.
- both
id
in ui and server should be same. -
inputData
in server should be format of reactive
Structure of kmsModule
treeModule is consisted with Control Area
and
Result Area
and below using flow.
- Declare module (we did already)
- select
K
- build
Cluster
If data has different scale (not normalized), check
scale
.If data has label (name), you can select if as
Labels-Opt
Usage of kmsModule
Using USArrests
, we’ll group city by their
similarity.
Set K as 4
For any issue or suggestion, please make issue in soroban’s github.