2016-09-10 2 views
0

임의로 생성 된 data.frame이 있습니다. 사용자는 슬라이더를 수정하여 포인트 수를 선택할 수 있습니다. 그런 다음이 data.frame을 그립니다.R Shiny : 데이터를 업데이트하는 버튼을 만듭니다. 프레임

클릭했을 때보 다 버튼을 추가하고 싶습니다. 이전 무작위로 생성 된 data.frame에서 수정을 수행합니다 (단, data.frame은 다시 생성하지 않음). 수정은 voronoid relaxation이며 버튼을 클릭 할 때마다 그래프를 생성해야합니다.

는 지금까지, 나는 ...

ui.R

을 아무것도 비슷한 달성하지
library(shiny) 

# Define UI for application that draws a histogram 
shinyUI(fluidPage(

    # Application title 
    titlePanel("Map Generator:"), 

    # Sidebar with a slider input for the number of bins 
    sidebarLayout(
    sidebarPanel(
     p("Select the power p to generate 2^p points."), 
     sliderInput("NumPoints", 
        "Number of points:", 
        min = 1, 
        max = 10, 
        value = 9), 
     actionButton("GenPoints", "Generate"), 
     actionButton("LloydAlg", "Relaxe") 
    ), 

    # Show a plot of the generated distribution 
    mainPanel(



     plotOutput("distPlot",height = 700, width = "auto") 
    ) 
) 
)) 

server.R 내가 뭘해야 뭔가가 물론

library(shiny) 
library(deldir) 

shinyServer(function(input, output) { 


    observeEvent(input$NumPoints,{ 

    x = data.frame(X = runif(2^input$NumPoints,1,1E6), 
        Y = runif(2^input$NumPoints,1,1E6)) 

    observeEvent(input$LloydAlg, { 
     x = tile.centroids(tile.list(deldir(x))) 
    }) 

    output$distPlot <- renderPlot({ 
     plot(x,pch = 20,asp=1,xlim=c(0,1E6),ylim = c(0,1E6)) 
    }) 

    }) 
}) 

틀린,하지만 나는 아주 새롭다. 나는 내가 잘못하고있는 것을 알아낼 수 없다 ...

답변

1

(비록 이것이 개선 될 수 있을지는 꽤 확신한다.) :

shinyServer(function(input, output) { 
    library(deldir) 

    data = data.frame(
    X = runif(2^9, 1, 1E6), 
    Y = runif(2^9, 1, 1E6) 
) 

    rv <- reactiveValues(x = data) 

    observeEvent(input$GenPoints, { 
    rv$x <- data.frame(
     X = runif(2^input$NumPoints,1,1E6), 
     Y = runif(2^input$NumPoints,1,1E6) 
    ) 
    }) 
    observeEvent(input$LloydAlg, { 
    rv$x = tile.centroids(tile.list(deldir(rv$x))) 
    }) 

    output$distPlot <- renderPlot({ 
    plot(rv$x,pch = 20,asp=1,xlim=c(0,1E6),ylim = c(0,1E6)) 
    }) 
}) 

먼저 점을 플롯으로 초기화한다. sliderInput의 시작 값이 항상 9이므로 runif(2^9, 1, 1E6)을 사용합니다.

또한 sliderInput에서 observeEvent을 제거하고 GenPoints actionButton으로 옮겼습니다.

관련 문제