2017-01-31 9 views
0

Ich weiß, dass dies eine grundlegende Frage ist, aber ich bin wirklich neu bei Shiny ...SelectInput und wenn Schleife Plot R Shiny

Wie kann ich kombinieren plotlyOutput mit einer if-Schleife von einer SelectInput Box?

Ich meine etwas wie folgt aus:

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

Aber es funktioniert nicht.

+1

Meine Vermutung: Ersetzen Sie "Vars $ location ==" AP LIGUA "' mit 'input $ myLocations ==" AP LIGUA "'. – Axeman

+0

"Fehler: Objekt 'Eingabe' nicht gefunden" – NUForever

Antwort

1

Ich nehme an, Sie haben Ihren Code abgeschnitten? Es sieht nicht sehr nach einer glänzenden App aus. So sollte eine glänzende App aussehen.

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

Ja, ist abgeschnitten. Aber ich denke, ich habe mein Problem schlecht erklärt ... Was ich tun möchte, ist eine andere Grafik zu zeichnen, wenn ich eine andere Option auswähle. Ich versuche mit Ihrer Antwort, aber es immer plotten, wenn "AP LIGUA" ausgewählt ist oder nicht. if (is.null (Eingabe $ myLocations) == "AP LIGUA") return() Ich meine so etwas wie – NUForever

+0

Ich habe keine Ahnung, was Sie planen. Teilen Sie Ihren 'plot_ly' Code bitte – Jean

+0

hier ist mein Code https://drive.google.com/open?id=0B1Akou7WM7XFNFlJYmVpNW1fTWs – NUForever

Verwandte Themen