图表和数据表选择之间闪烁的数据框范围问题

时间:2017-11-21 11:31:46

标签: r shiny dt

我从SQL查询创建一个dataTable,我希望使用输入$ table_rows_selected函数(单击DT Table行视图)来更新图形

我的问题是输出$ plot< - renderPlotly函数(范围问题)

看不到创建的表

如何在我的dataTable和我的图形之间进行此交互(包括彼此不同的SQL查询)?

感谢您的帮助

这是我的UI.R:

  mainPanel(
   DT::dataTableOutput("table"), #My Table 
  plotlyOutput("plot")) # My graph
   ))

 refDataFrame <- reactive({
 data_testeur <- odbcConnect(input$base, uid="uid")

 SQL query searching all STEP_NAME items
 odbcClose(data_testeur)

Ref_comp

})

这里是server.R:

   output$Table <- DT::renderDataTable({

   data_testeur <- odbcConnect(input$base, uid="uid")

    SQL query to feed my dataTable with a column including all items 
                                                         STEP_NAME
     Close connexion data_testeur

     cpk_total created from the SQL query

     DT::datatable(cpk_total,...) # Formating table
      )


     output$plot <- renderPlotly({

    data_testeur <- odbcConnect(input$base, uid="uid")

      another SQL query to trace the graph for 1 STEP_NAME selected
      #This SQL query use a variable from the created cpk_total table

     Close connexion data_testeur

     graph <- ....

       )

1 个答案:

答案 0 :(得分:0)

将data.table的代码放在像这样的反应中

cpk_total <- reactive({
 data_testeur <- odbcConnect(input$base, uid="uid")

    SQL query to feed my dataTable with a column including all items 
                                                         STEP_NAME
     Close connexion data_testeur

     return result created from the SQL query
})

adnd然后在DT::renderDataTable中调用它

output$Table <- DT::renderDataTable({
     DT::datatable(cpk_total(),...) # Formating table
      })

并且在renderPlotly中您也可以访问它

output$plot <- renderPlotly({
    dta <- cpk_total()
    data_testeur <- odbcConnect(input$base, uid="uid")

      another SQL query to trace the graph for 1 STEP_NAME selected
      #This SQL query use a variable from the created cpk_total table

     Close connexion data_testeur

     graph <- ....

       )

反应性的好处是 - 它仍然只计算一次: - )

希望这有帮助