source("getFreqMtxDir.R")
library(manipulate)
出力画面
manipulate({
res <- getFreqMtxDir("../univ", rela = relative, tfidf = TFIDF)
mtx <- t(res)
hc <- hclust(dist(mtx, method = dist_method), method = "ward")
plot(hc)
rect.hclust(hc, k = clust_num, border = "red")
}, relative = checkbox(FALSE, "Relative Freq"), TFIDF = picker(0, 1, 2), dist_method = picker("euclidean",
"canberra", "manhattan"), clust_num = slider(2, 5))
install.packages("shiny")
library(shiny)
runApp("www1")
shinyUI(bootstrapPage(
# Application title
headerPanel("前回の課題1"),
# Sidebar
sidebarPanel(
#relative=checkbox(FALSE, "Relative Freq")
checkboxInput(inputId = "relative",
label = strong("Relative Freq"),
value = FALSE),
#TFIDF=picker(0,1,2)
selectInput(inputId ="TFIDF",
label = "Choose a TF-IDF option:",
choices = c(0,1,2),
selected = 0),
#dist_method=picker("euclidean","canberra","manhattan")
selectInput(inputId ="dist_method",
label = "Choose a distance method:",
choices = c("euclidean","canberra","manhattan"),
selected = "canberra"),
#clust_num=slider(2,5)
sliderInput(inputId = "clust_num",
label = "Cluster num: ",
min = 2, max = 5, value = 2)
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("main_plot")
)
))
shinyServer(function(input, output) {
output$main_plot <- renderPlot({
res <- getFreqMtxDir("../univ", rela=input$relative, tfidf=input$TFIDF)
mtx<-t(res)
hc <-hclust(dist(mtx, method=input$dist_method), method="ward")
plot(hc)
rect.hclust(hc, k = input$clust_num, border = "red")
})
})
runApp("www2")
manipulate({
res <- getFreqMtxDir("../univ")
mtx <- res[rownames(res) %in% names(df[df == common_text]), ]
hc <- hclust(dist(mtx, method = dist_method), method = cluster_method)
plot(hc)
}, common_text = slider(4, 7), dist_method = picker("euclidean", "canberra",
"manhattan"), cluster_method = picker("ward", "complete", "average"))
runApp("www3")
出力画面
コントローラーにクラスター枠描画チェックボックス(draw_rect)を追加
shinyUI(bootstrapPage(
....
# Sidebar
sidebarPanel(
....
checkboxInput(inputId = "draw_rect",
label = strong("Draw Rectangles"),
value = FALSE),
#clust_num=slider(2,5)
....
),
....
))
if(input$draw_rect){
rect.hclust(hc, k = input$clust_num, border = "red")
}
draw_rect “TRUE"のときに、clust_numスライダーを表示
shinyUI(bootstrapPage(
....
# Sidebar
sidebarPanel(
....
#clust_num=slider(2,5)
conditionalPanel(condition = "input.draw_rect == true",
sliderInput(inputId = "clust_num",
label = "Cluster num: ",
min = 2, max = 5, value = 2))
....
),
....
))
clust_numの上限をデータ依存に変更
shinyUI(bootstrapPage(
....
# Sidebar
sidebarPanel(
....
conditionalPanel(condition = "input.draw_rect == true",
uiOutput("cnumControls"))
....
),
....
))
output$cnumControls <- renderUI({
sliderInput("clust_num", "Cluster num: ",
min = 2, max = ncol(res)-2, value = 2, step=1)
})
runApp("www2")
shinyUI(bootstrapPage(
# Application title
headerPanel("前回の課題1"),
# Sidebar
sidebarPanel(
#relative=checkbox(FALSE, "Relative Freq")
checkboxInput(inputId = "relative",
label = strong("Relative Freq"),
value = FALSE),
#TFIDF=picker(0,1,2)
selectInput(inputId ="TFIDF",
label = "Choose a TF-IDF option:",
choices = c(0,1,2),
selected = 0),
#dist_method=picker("euclidean","canberra","manhattan")
selectInput(inputId ="dist_method",
label = "Choose a distance method:",
choices = c("euclidean","canberra","manhattan"),
selected = "canberra"),
checkboxInput(inputId = "draw_rect",
label = strong("Draw Rectangles"),
value = FALSE),
#clust_num=slider(2,5)
#conditionalPanel(condition = "input.draw_rect == true",
# sliderInput(inputId = "clust_num",
# label = "Cluster num: ",
# min = 2, max = 5, value = 2))
conditionalPanel(condition = "input.draw_rect == true",
uiOutput("cnumControls"))
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("main_plot")
)
))
shinyServer(function(input, output) {
output$cnumControls <- renderUI({
sliderInput("clust_num", "Cluster num: ",
min = 2, max = ncol(res)-2, value = 2, step=1)
})
output$main_plot <- renderPlot({
res <- getFreqMtxDir("../univ", rela=input$relative, tfidf=input$TFIDF)
mtx<-t(res)
hc <-hclust(dist(mtx, method=input$dist_method), method="ward")
plot(hc)
if(input$draw_rect){
rect.hclust(hc, k = input$clust_num, border = "red")
}
})
})
shinyUI(bootstrapPage(
# Application title
headerPanel("類似度計算"),
# Sidebar
sidebarPanel(
selectInput(inputId ="simil_method",
label = "Choose a similarity method:",
choices = c("correlation","cosine"),
selected = "correlation")
),
# Show a plot of the generated distribution
mainPanel(
verbatimTextOutput("main_plot")
)
))
shinyServer(function(input, output) {
output$main_plot <- renderPrint({
library(proxy)
print(input$simil_method)
res <- getFreqMtxDir("../univ")
simil(t(res), method=input$simil_method)
})
})
runApp("www4")
shinyUI(bootstrapPage(
# Application title
headerPanel("類似度計算"),
# Sidebar
sidebarPanel(
selectInput(inputId ="simil_method",
label = "Choose a similarity method:",
choices = c("correlation","cosine"),
selected = "correlation")
),
# Show a plot of the generated distribution
mainPanel(
verbatimTextOutput("main_plot")
)
))
shinyServer(function(input, output) {
output$main_plot <- renderPrint({
library(proxy)
print(input$simil_method)
res <- getFreqMtxDir("../univ")
simil(t(res), method=input$simil_method)
})
})
runApp("www5")
runApp("www6")
出力画面