2016-11-23 6 views
-1

viewportに円を描こうとしていますが、出力はテキストのみです。私の究極の目的は、プロットの上に円を描くことです。R(Shiny)grid.circleとviewport出力のテキストのみ

library(reshape) 
library(grid) 

ui <- fluidPage(
    titlePanel("The Bomb Problem"), 
    fluidRow(
    column(2, numericInput("numberOfPoints", "Number Of Points:", 0)), 
    column(2, numericInput("radius", "Radius:", 0.5, min = 0, max = 1)), 
    column(2, actionButton("btnRun", "Run")) 

), 
    mainPanel(
    vp <- viewport(x=0.5,y=0.5,width=0.9, height=0.9), 
    pushViewport(vp), 
    plotOutput(outputId = "points", width = "100%"), 
    grid.circle(x=0.6, y=0.4, r=0.3, draw = TRUE) 
) 
) 
server <- function(input, output) { 
    observeEvent(input$btnRun, { 
    x<-sample(0:input$numberOfPoints, input$numberOfPoints, rep=TRUE) 
    y<-sample(0:input$numberOfPoints, input$numberOfPoints, rep=TRUE) 
    output$points <- renderPlot(plot(x, y), height = 800, width = 800) 
    df <- melt(data.frame(x,y)) 
    }) 
} 
shinyApp(ui, server) 

しかし、私が得る唯一の出力は次のとおりです:これは私のコードですつまり

0.5npc 0.5npc 0.9npc 0.9npc centre FALSE 0 0 0 0.5 GRID.VP.13 

0.6npc 0.4npc 0.3npc GRID.circle.10 

grid.circleviewportは任意のオブジェクト、彼らだけの出力そのプロパティを描いていません。

答えて

0

私はそれを最後に理解しました。 observeEvent内のrenderPlotメソッドに円とプロットの両方をプロットすることにより、次のようになります。

require(plotrix) 
require(grid) 
require(reshape) 

ui <- fluidPage(
    titlePanel("The Bomb Problem"), 
    fluidRow(
    column(2, numericInput("numberOfPoints", "Number Of Points:", 0)), 
    column(2, numericInput("radius", "Radius:", 0.5, min = 0, max = 1)), 
    column(2, actionButton("btnRun", "Run")) 

), 
    mainPanel(
    plotOutput(outputId = "points", width = "100%") 
) 
) 
server <- function(input, output) { 
    observeEvent(input$btnRun, { 
    x<-sample(0:input$numberOfPoints, input$numberOfPoints, rep=TRUE) 
    y<-sample(0:input$numberOfPoints, input$numberOfPoints, rep=TRUE) 
    output$points <- renderPlot({ 
     plot(x, y) 
     draw.circle(0.5, 0.5, (input$numberOfPoints/2) * input$radius, nv = 1000, border = NULL, col = NA, lty = 1, lwd = 0.5) 
    }, height = 800, width = 800) 
    df <- melt(data.frame(x,y)) 

    }) 
} 
shinyApp(ui, server) 
関連する問題