Return output function based on selectInput tabPanel using R Shiny

54 views
Skip to first unread message

lara.faelivrin

unread,
May 4, 2016, 10:22:02 AM5/4/16
to Shiny - Web Framework for R
My aim is to change the output function of the `main panel` (`leafletOutput and plotOutput`) in dependence of the `selectInput` widget in the `tabPanel`. I thought this can be accomplished with an if clause (e.g.,  `if(input$evaluation == "Map"){` ; `if(input$evaluation == "Evaluation"){`). This, however, does not work as expected as it only returns the output function that is listed first in the UI script. Am I doing something wrong or is there any other way how this can be accomplished?



    #=================================================
    # Library
    #=================================================
    library(shiny)
    library(raster)
    library(mgcv) # overwrites gam from standard R package
    library(FNN)
    library(spatstat)
    library(PresenceAbsence)
    library(rgdal)
    library(maptools)
    library(dismo)
    library(leaflet)
    library(shinyjs)
    
    #=================================================
    # Data
    #=================================================
    load("/home/Desktop/Test.RData")
    
    #=================================================
    # Coordinates of the 1st taxon (showed after app-start)
    #=================================================
    sel_taxon <-names(Test[[1]]) 
    dat <- Test[[1]]
    sel_coord <- paste(dat$x_swiss,dat$y_swiss, sep='_')
    
    #=================================================
    # UI
    #=================================================
    ui <- navbarPage("Test Toolbox", id="nav", ## UI
                     
                     tabPanel(value= "taxon", ## placement
                              selectInput("taxon", label = "Taxon", choices = sort(names(Test))) ## widget
                              
                     ),
                     tabPanel(value= "coordinate", ## placement
                              selectInput("coordinate", label = "Coordinate", choices = sel_coord) ## widget
                     ),
                     tabPanel(value= "evaluation", ## placement
                              #selectInput("evaluation", label = "Evaluation", choices = list("Map", "Evaluation")) ## widget
                              selectInput("evaluation", label = "Evaluation", choices = list("Map", "Evaluation")) ## widget
                              
                     ),
                     
                     mainPanel(
                       
                     div(class="outer", ## placement
                         tags$head(
                           # Include our custom CSS
                           includeCSS("/home/Desktop/Shiny_Test/styles.css")
                           # includeScript("gomap.js")
                         ),
                         
                         #leafletOutput("map", width="100%", height="100%"), ## output function
                         plotOutput("evaluation", width="100%", height="90%")  ## output function
                         #verbatimTextOutput("test"),
                         #textOutput("evaluation")
                         
                     )))
    #=================================================
    # Server
    #=================================================
    server <- function(input, output, session) {
      
      observe({
        dat <- Test[[input$taxon]]
        updateSelectInput(session, "coordinate", choices =  paste(dat$x_swiss, dat$y_swiss, sep='_'))
        })
    
     observe({
       
     if(input$evaluation == "Map"){
    
      output$map <- renderLeaflet({
    #….
    
    })
    }
    })
    
     
    
    observe({ 
      
      
      if(input$evaluation == "Evaluation"){
        
        output$evaluation <- renderPlot({
    
    #….
    
    })
    }
    })   
       
    }

Reply all
Reply to author
Forward
0 new messages