R有光泽:交互式切换点(nearPoints()),动态数据选择在更新后出错

时间:2017-01-20 17:54:00

标签: r shiny

我对我构建的闪亮应用有疑问。我分享的应用程序工作正常,直到我更新了我的ggplot2包。我收到一条错误消息:Error in nearPoints: nearPoints: not able to automatically infer xvar from coordinfo。我不知道它为什么有效,但现在它无法正常工作。

此应用程序的想法是使用所选数据输入构建交互式散点图。

任何人都可以帮我弄清楚为什么会出现这个错误吗?

这是app.r:

library(shiny)    
ui <- fluidPage(
    fluidRow(
    column(width = 6,
           selectInput("vsselection", "Choose a vs:", 
                       choices =       names(table(data.frame(mtcars$vs))),selected=0),
           plotOutput("plot1", height = 350,
                      click = "plot1_click",
                      brush = brushOpts(
                        id = "plot1_brush"
                      )
           ),
           actionButton("exclude_toggle", "Toggle points"),
           actionButton("exclude_reset", "Reset")
      )
     )
    )
server <- function(input, output) {
# For storing which rows have been excluded
vals <- reactiveValues(
keeprows = rep(TRUE, nrow(mtcars))
)

output$plot1 <- renderPlot({
# Plot the kept and excluded points as two separate data sets
keep    <- mtcars[which(mtcars$vs==input$vsselection),][ vals$keeprows, ,    drop = FALSE]
exclude <- mtcars[which(mtcars$vs==input$vsselection),][!vals$keeprows, , drop = FALSE]

ggplot(keep, aes(wt, mpg)) + geom_point(color = "blue") +
  geom_smooth(method = lm, fullrange = TRUE, color = "black") +
  geom_point(data = exclude, shape = 21, fill = NA, color = "black", alpha =   0.25) 
})

# Toggle points that are clicked
observeEvent(input$plot1_click, {
res <- nearPoints(mtcars[which(mtcars$vs==input$vsselection),],   input$plot1_click, allRows = TRUE)

vals$keeprows <- xor(vals$keeprows, res$selected_)
})

# Toggle points that are brushed, when button is clicked
observeEvent(input$exclude_toggle, {
res <- brushedPoints(mtcars[which(mtcars$vs==input$vsselection),],  input$plot1_brush, allRows = TRUE)

vals$keeprows <- xor(vals$keeprows, res$selected_)
})

# Reset all points
observeEvent(input$exclude_reset, {
vals$keeprows <- rep(TRUE,    nrow(mtcars[which(mtcars$vs==input$vsselection),]))
})

}


shinyApp(ui, server)

1 个答案:

答案 0 :(得分:0)

我通过将“闪亮”软件包版本更新为1.0.0来弄明白。因此,如果您使用的是旧版本,则会发出警告:Warning in seq_len(nrow(layout)) : first element used of 'length.out' argument。这与包的版本有关。