I have a Select Box Input which changes based on the column names of the loaded .csv
file. This is what my observeEvent
function does.
I am having trouble when I go to plot the output in server.R
, because I am unsure how to craft the reactive argument to transform the output of the SelectizeInput
to the column that was chosen from the SelectBox. Does anyone know what I should put inside of the renderDygraph
output that will graph the channel that I chose from my SelectizeInput
?
Here is my code:
ui.R
shinyUI(fluidPage(
# Application title
titlePanel("Graph"),
fluidRow(
column(6,
wellPanel(`
selectInput("dataSelection1", label = "Choose a File",
choices = c("File1")),
selectizeInput("channel1", label = "Choose a Channel",
choices = NULL))),
column(12, dygraphOutput("Graph")
)
)
)
)
server.R
shinyServer(function(input, output, session) {
dataSource1 <- reactive({
switch(input$dataSelection1,
"File1" = File1)
})
observeEvent(input$dataSelection1, {
updateSelectizeInput(session, 'channel1', choices = names(dataSource1()))
})
output$TempRise <- renderDygraph({
component <- switch(input$channel1,
**'WHAT TO PUT IN HERE?'**)
dygraph(component, main = "Data Graph") %>%
dyRangeSelector() %>%
dyOptions(colors = RColorBrewer::brewer.pal(8, "Dark2"))
})
})
I don't think you can use a switch statement as you don't know ahead of time what to equate it to, but I do something like this:
shinyServer(function(input, output, session) {
dataSource1 <- reactive({
switch(input$dataSelection1,
"File1" = File1)
})
observeEvent(input$dataSelection1, {
updateSelectizeInput(session, 'channel1', choices = names(dataSource1()))
})
output$TempRise <- renderDygraph({
data <- dataSource1()
selected_input <- input$channel1
component <- data[, selected_input]
dygraph(component, main = "Data Graph") %>%
dyRangeSelector() %>%
dyOptions(colors = RColorBrewer::brewer.pal(8, "Dark2"))
})
})