値sliderInputに基づいてデータをサブセット化する以外の何もしないリアクティブ関数(datasplit)があります。 私の2番目のリアクティブ関数(selectedData)は、最初のリアクティブ関数からサブセットデータを取り出し、SelectInputに基づいて列を再度フィルタリングする必要があります。リアクティブ関数間でデータを渡す - Shiny R
最後にこのデータに基づいてクラスタリングします。
SelectInputから入力を受け取りますが、最初はリアクティブ関数では機能しません。
ありがとうございました。私はデータをアップロードできませんが、私の輝くコードを参照してください。
シャイニーコード:
library(shiny)
ui <- fluidPage(
selectInput("xcol", "X Variable", names(data[,c(2)])),
selectInput("ycol", "Y Variable", names(data[,c(1)])),
sliderInput(inputId = "cost",
label = "Kosten",
value = 1000, min = 1, max = 5000),
sliderInput(inputId = "count",
label = "Anzahl Fälle",
value = 500, min = 1, max = 2000),
numericInput("clusters", "Anzahl Cluster", 3, min=1, max= 9),
plotOutput(outputId = "plot1")
)
server <- function(input, output){
DealerDF <- read.csv(file = "dealer_category.csv",header = T)
data <- DealerDF
datasplit <- reactive({
subset(data, input$xcol() < input$cost() & input$ycol() < input$count())
})
selectedData <- reactive({
#this seems to be not working
datasplit()[, c(input$xcol(), input$ycol())]
})
clusters <- reactive({
kmeans(selectedData(), input$clusters)
})
output$plot1 <- renderPlot({
if (!is.null(selectedData())) {
par(mar= c(5.1, 4.1,0,1))
plot(selectedData(),
col= clusters()$cluster,
pch= 20, cex=3)
points(clusters()$centers, pch=4, cex=4, lwd=4)
}
})
}
shinyApp(ui = ui, server = server)
データ:
cnt av_cst
479 2.359.695
479 83.439
475 891.863
474 2.496.681
474 97.654
474 821.163
473 1.650.016
473 143.724
472 90.398
470 98.745
468 681.947
468 97.392
467 435.477
467 97.657
466 160.547
463 98.454
30 24.936
30 29.432
30 1.599.577
30 227.073
30 227.887
30 187.147
30 89.697
30 615.427
30 32.398
30 15.133
30 24.445.753
30 25.944
30 344.933
30 10.237
30 15.86
17082 30.425
11358 75.541
9788 30.638
9667 30.381
7302 73.051
6849 1.009.921
6299 124.441
6018 30.158
5646 124.569
5383 1.133.911
5381 30.278
4357 123.213
3989 3.065
外の関数kmeans計算を移動することを検討可能性があります'? –
@PorkChopデータは25列のデータフレームです – user3560220
データを入力してください –