2015-08-27 59 views
1

我的计划是导入一个名为rawdata的大型原始数据集,然后使用sourced scripts.R文件对数据集进行一些调整。消除的数据以tidyr :: gather命名的heap创建的几个数据帧列表的形式传回server.R。闪亮:使用reactiveValues的ggplot交互性中的反应性上下文错误

接下来,我想要显示一个heap[[2]]heap[[10]]的ggplot。

使用Shiny网站上的示例图交互,我希望能够从图中刷掉明显异常的点。但是,我遇到了一个令人讨厌的反应性上下文错误,我无法调试。我相当肯定,它涉及线路77〜80:

vals.temp <- reactiveValues(
if(!is.null(heap())) { 
    keeprows = rep(TRUE, nrow(heap()[[2]])) 
}) 

在提供的闪亮网站上的例子,它使用mtcars数据集,但我是一个数据集反应基于用户输入。我怀疑某处有断开连接。

链接到文件: Dropbox

非常感谢你的专长!

回答

1

你可以声明一个空的列表vals <- reactiveValues(),然后你可以添加一个元素some <- reactive({ ... vals$keeprows <- nrow...})

在下面的示例plotOutput('figure')现在是交互式的。我用闪亮画廊中提到的例子。

的服务器脚本的关键部分:

output$AddCustom <- renderUI(
    AddCustomInputs() 
) 


    # Based on data() variables column, populate a selectInput called "subset" with variable data 
    output$selector <- renderUI({ 
    selectInput('subset', 'Graph Parameter', choices = levels(heap()[[1]]$variable)) 
    }) 

    # Changes from here: ---------------------------------------------------------------------- 

    vals <- reactiveValues() # keeprows = rep(TRUE, 100000) 

    # Subset the data() set by the value selected in the "subset" selectInput and save it as df() 
    df <- reactive({ 

    vals$keeprows <- rep(TRUE, nrow(heap()[[1]][heap()[[1]]$variable %in% input$subset, ])) 

    return(heap()[[1]][heap()[[1]]$variable %in% input$subset, ]) 
    }) 


    observeEvent(input$exclude_toggle, { 
    res <- brushedPoints(df(), input$figure_brush, allRows = TRUE) 

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

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


    # create a plot based on df() 
    output$figure <- renderPlot({ 

    keep <- df()[ vals$keeprows, , drop = FALSE ] 

    if(!is.null(df())) { 
     plot <- isolate(
     ggplot(data = na.omit(keep), aes(x = NST_DATI, y = value)) + 
      geom_line() + 
      labs(x = "Date", y = input$subset, title = paste(input$subset, "vs. Date")) 
    ) 
     return(plot) 
    } 
    }) 
    output$table <- renderDataTable(
    if(!is.null(rawdata())) { 
     return(rawdata()) 
    } 
) 
}) 

UI脚本:

shinyUI(fluidPage(
    titlePanel("Data Fix-it"), 
    sidebarLayout(
     sidebarPanel(
     fileInput('rawfile', 'Input *.CSV'), 
     helpText("Files downloaded from ADRS Console must be saved as *.csv for import."), 
     h4("Other Parameters"), 
     tags$body("Only the 'Big 7' parameters will be retained, unless specified."), 
     br(), 
     checkboxInput('AddCustomCheck', 'Add custom parameters'), 
     uiOutput('AddCustom'), 
     hr(), 
     numericInput('sequnceminutes', 'Water Quality Interval (mins)', value = 60), 
     actionButton('groomgo', 'Groom Data'), 
     textOutput('linesaltered'), 
     hr(), 
     downloadButton('downloadcsv', 'Download *.csv file') 
    ), 
     mainPanel(
     tabsetPanel(
      tabPanel("Plot", 
        uiOutput('selector'), 
        plotOutput('figure', brush = brushOpts(id = "figure_brush")), 

        actionButton("exclude_toggle", "Toggle points"), 
        actionButton("exclude_reset", "Reset") 
     ), 
      tabPanel("Table", 
        dataTableOutput('heaptable')), 
      tabPanel("Report", 
        actionButton('MakePlotsgo', 'Make Plots'), 
        plotOutput('heaptemp'), 
        plotOutput('heapph'), 
        plotOutput('heapcond'), 
        plotOutput('heaptds'), 
        plotOutput('heapdomgl'), 
        plotOutput('heapdosat'), 
        plotOutput('heapturb'), 
        plotOutput('heapflow'), 
        plotOutput('heapcustom1'), 
        plotOutput('heapcustom2'), 
        plotOutput('heapcustom3') 
     ) 
     ) 
    ) 
    ))) 

我希望这是你想要的东西:)

+0

谢谢你这么多的去上面和 - 超越。 –