2016-10-25 32 views
0

我建立了一个闪亮的应用程序与数据库后端 -更新数据框后重绘闪亮绘图?

我试着重新加载数据框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)) 
         }) 

}) 

回答

1

片断你可能需要做current_data_frame反应值。你可以做到这一点通过它返回一个reactive内或将其添加到您的vals对象,包括使用vals$current_data_frame无处不在,你目前使用的current_data_frame和改变vals看起来是这样的:

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

将设置vals$current_data_frame到第一次在代码开始时定义的默认值,然后允许您在每次触发observeEvent时更改它。

+0

试了第二个选项,仍然没有任何反应的行动,我也必须从你的片段删除前面的逗号寿 – user3234810

+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)) 
         }) 

        }) 

})