你可以声明一个空的列表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')
)
)
)
)))
我希望这是你想要的东西:)
谢谢你这么多的去上面和 - 超越。 –