2016-09-10 20 views
0

ランダムに生成されたdata.frameがあります。スライダを変更してポイント数を選択することができます。それから私はこのdata.frameをプロットします。R Shiny:data.frameを更新するボタンを作成します。

クリックしたときよりもボタンを追加したいのですが、以前にランダムに生成されたdata.frame(ただしdata.frameを再生成しません)で変更を行います。変更はボロノイド緩和であり、ボタンがクリックされグラフが生成されるたびに1回実行する必要があります。

今まで、私は似た何かを達成していない...もちろん

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

このshou LDの仕事(私はこれが改善される可能性がかなり確信しているにもかかわらず):

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に移動しました。

関連する問題