2017-01-31 31 views
0

我知道這是一個基本的問題,但我真的很新的閃亮......SelectInput如果循環情節[R閃亮

我怎麼能結合plotlyOutput與來自SelectInput框中如果循環?

我的意思是這樣的:

vars <- data.frame(location = c("AP LIGUA", 
          "ESCUELA CHALACO"), 
       lat = c(-32.45, 
         -32.183333), 
       lon = c(-71.216667, 
         -70.802222) 
) 

selectInput(inputId = "myLocations", label = "Estación", 
               choices = vars$location), 
if (vars$location=="AP LIGUA") { 
           plotlyOutput("apligua", height = "100%") 
           fluidRow(
            DT::dataTableOutput("table") 
           ) 
           } 

但它不工作。

+1

我的猜測是:用'input $ myLocations =='AP LIGUA「'替換'vars $ location ==」AP LIGUA「'。 – Axeman

+0

「錯誤:找不到對象'輸入'」 – NUForever

回答

1

我想你截斷了你的代碼?它看起來不像一個閃亮的應用程序。這是一個閃亮的應用程序應該看起來像。

vars <- data.frame(location = c("AP LIGUA", 
          "ESCUELA CHALACO"), 
       lat = c(-32.45, 
         -32.183333), 
       lon = c(-71.216667, 
         -70.802222) 
) 

ui <- fluidPage(
    selectInput(inputId = "myLocations", label = "Estación", 
               choices = vars$location), 
    plotlyOutput("apligua", height = "100%"), 
    dataTableOutput("table") 
) 

server <- function(input, output,session) { 

    output$apligua <- renderPlotly({ 
    if(is.null(input$myLocations)) return() #react to the user's choice if there's one 

    plot_ly(...) 
    }) 

    output$table <- renderDataTable({ 
    if(is.null(input$myLocations)) return() #same thing, react to the user's choice 

    data.table(...) 
    }) 
} 

shinyApp(ui, server) 
+0

是,被截斷。但我認爲我解釋了我的問題很糟糕......我想要做的是在選擇不同的選項時繪製不同的圖表。 我試着回答你的答案,但如果選擇了「AP LIGUA」,它總是會出現陰謀。如果(is.null(input $ myLocations)==「AP LIGUA」)return() 我的意思是這樣 – NUForever

+0

我不知道你在繪製什麼。請分享您的'plot_ly'代碼 – Jean

+0

這裏是我的代碼 https://drive.google.com/open?id=0B1Akou7WM7XFNFlJYmVpNW1fTWs – NUForever