更新数据框后重绘闪亮的情节?

时间:2016-10-25 18:11:39

标签: r shiny

我已经构建了一个带有数据库后端的Shiny应用程序 -

我尝试重新加载数据框current_data_frame并在按下input$draw_plot(操作按钮)时使用它重绘图。

在调用数据框后,我无法重新绘制图表?

我想念的任何想法?

来自server.R的

片段

  current_data_frame = data.frame(matrix(ncol = 4, nrow = 0))
  names( current_data_frame ) <- c("sample_id", "call", "intensity_A" , "intensity_B")


  # OBSERVE BUTTON PRESS & UPDATE DATA FRAME
  observeEvent( input$draw_plot, {
                current_data_frame <- get_data_frame( input$probeset_id , input$study_id , input$batch_id)

                }) 

  vals <- reactiveValues(
                        keeprows = rep(TRUE, nrow( current_data_frame ))
                        )

  output$call_plot <- renderPlot({
                        # Lists for holding unactive_points                      
                        keep    <- current_data_frame[ vals$keeprows, , drop = FALSE]
                        exclude <- current_data_frame[ !vals$keeprows, , drop = FALSE]
                        # Le plot 
                        ggplot(keep, aes( intensity_A , intensity_B)) +
                          geom_point(aes(colour = factor(call), shape = factor(call)) )  #+ 
                          #geom_point(data = exclude, shape = 21 , fill = NA, colour = "black", alpha = 0.25)

                        })

                        # Toggle click points 
                        observeEvent( input$call_plot_click, {
                          res <- nearPoints(current_data_frame, input$call_plot_click, allRows = TRUE)

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

                        # Toggle points that are brushed when clicked 

                        observeEvent(input$exclude_toggle, {
                          res <- brushedPoints(current_data_frame, input$call_plot_brush, allRows = TRUE)

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

                        # Reset all points 

                        observeEvent( input$exclude_reset, {
                          vals$keeprows <- rep( TRUE, nrow(current_data_frame))
                        })

})  

2 个答案:

答案 0 :(得分:1)

您可能需要使current_data_frame成为无效值。您可以通过将其返回到reactive内或将其添加到vals对象来执行此操作,包括在当前使用vals$current_data_frame的任何位置使用current_data_frame并更改{{1}看起来像这样:

vals

会将vals <- reactiveValues(keeprows = rep(TRUE, nrow( current_data_frame )), current_data_frame = current_data_frame ) 设置为您第一次在代码开头定义的默认值,然后允许您在每次触发vals$current_data_frame时更改它。

答案 1 :(得分:0)

管理自己回答 -

在响应函数中包含整个输出$ call_plot。现在,每次按下按钮时,它都会重绘+获取新数据。

以下代码......

observeEvent( input$draw_plot, {
                current_data_frame <- get_data_frame( input$probeset_id , input$study_id , input$batch_id)



  vals <- reactiveValues(
                        keeprows = rep(TRUE, nrow( current_data_frame ))
                        )

  output$call_plot <- renderPlot({
                        # Lists for holding unactive_points                      
                        keep    <- current_data_frame[ vals$keeprows, , drop = FALSE]
                        exclude <- current_data_frame[ !vals$keeprows, , drop = FALSE]
                        # Le plot 
                        ggplot(keep, aes( intensity_A , intensity_B)) +
                          geom_point(aes(colour = factor(call), shape = factor(call)) )  #+ 
                          #geom_point(data = exclude, shape = 21 , fill = NA, colour = "black", alpha = 0.25)

                        })

                        # Toggle click points 
                        observeEvent( input$call_plot_click, {
                          res <- nearPoints(current_data_frame, input$call_plot_click, allRows = TRUE)

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

                        # Toggle points that are brushed when clicked 

                        observeEvent(input$exclude_toggle, {
                          res <- brushedPoints(current_data_frame, input$call_plot_brush, allRows = TRUE)

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

                        # Reset all points 

                        observeEvent( input$exclude_reset, {
                          vals$keeprows <- rep( TRUE, nrow(current_data_frame))
                        })

                    })  

})