2015-09-15 75 views
0

我有一個選擇框輸入,它根據加載的.csv文件的列名進行更改。這是我的observeEvent函數。如何從選擇性輸入中選擇反應性參數?

我在打印輸出到server.R時遇到了問題,因爲我不確定如何製作反應參數以將SelectizeInput的輸出轉換爲從SelectBox中選擇的列。有沒有人知道我應該在renderDygraph輸出內部放置什麼內容,這將顯示我從我的SelectizeInput中選擇的頻道?

這裏是我的代碼:

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")) 

    }) 

}) 

回答

1

我不認爲你可以使用switch語句,你不提前知道什麼時間等同於,但我做這樣的事情:

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")) 

    }) 

}) 
+0

謝謝你,@MarkeD這個伎倆! – Gary