-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path04_shiny.R
51 lines (41 loc) · 1.13 KB
/
04_shiny.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# app.R
library(shiny)
library(plotly)
library(RCurl)
# url<-"robles_desktop/home_shared/Jerome/"
# list.files(url)
# file.copy(paste(url,'!readme.txt',sep=''),tempfile())
#
# graph_data <- 'ftp://robles_desktop'
message(list.files('./'))
# Define UI
ui <- fluidPage(
titlePanel("Interactive Plotly App"),
sidebarLayout(
sidebarPanel(
fileInput("file", "Choose a CSV file",
accept = c("text/csv", "text/comma-separated-values,text/plain", ".csv")),
selectInput("x_variable", "X-axis Variable", ""),
selectInput("y_variable", "Y-axis Variable", "")
),
mainPanel(
plotlyOutput("plot")
)
)
)
# Define server
server <- function(input, output, session) {
data <- reactive({
req(input$file)
read.csv(input$file$datapath)
})
observe({
updateSelectInput(session, "x_variable", choices = names(data()))
updateSelectInput(session, "y_variable", choices = names(data()))
})
output$plot <- renderPlotly({
plot_ly(data(), x = ~get(input$x_variable), y = ~get(input$y_variable), type = "scatter", mode = "markers")
})
}
# Run the application
shinyApp(ui, server)