-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.R
32 lines (26 loc) · 826 Bytes
/
app.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
library(shiny)
library(ggplot2)
ui <- fluidPage(
fileInput(inputId = "upload_file", label = "File:"),
plotOutput(outputId = "view_plot"),
actionButton(inputId = "refresh", label = "View last plot")
)
server <- function(input, output, session) {
myPlot <- reactiveVal()
observeEvent(input$upload_file, ignoreInit = TRUE, {
if (!is.null(input$upload_file)) {
filepath <- input$upload_file$datapath
if (file.exists(filepath)) {
dataframe <- read.csv(file = filepath)
myPlot(ggplot(dataframe, aes(x = x, y = y)) + geom_line())
}
}
})
output$view_plot <- renderPlot({ print(myPlot()) })
observeEvent(input$refresh, ignoreInit = TRUE, {
if (!is.null(ggplot2::last_plot())) {
myPlot(ggplot2::last_plot())
}
})
}
shinyApp(ui = ui, server = server)