ConditionalPanel in Shiny results in selectInput error

I don't understand why mine is selectInput

n't working.

Once enabled, the conditionalPanel

sudden disconnection of names from John Doe to Joe Blow in selectInput

no longer works - the dates are not updated and the map turns gray.

I don't understand why this is happening. The only way it works is to click a button no_date

and then go back and change the name. Then everything shoots. But I can't figure out why / how it's broken.

Initially everything is in order:

enter image description here

But when I choose Joe Blow:

enter image description here

Please note that the date does not change.

Something strange is happening with conditionalPanel

, but for the life of me I'm stuck. Thanks for reading this.

UI.R

library(shiny)
library(ggplot2)
library(dplyr)
library(leaflet)


DF <- data.frame(lon=c(-120.6596156, -87.27751, -119.7725868, -124.2026, -117.1858759),  
                 lat=c(35.2827524, 33.83122, 36.7468422, 41.75575, 34.5008311), 
                 date=c('2014-03-14', '2014-01-11', '2013-11-22', '2012-08-23', '2013-08-23'),
                 city=c('San Luis Obispo', 'Jasper', 'Fresno', 'Crescent City', 'Apple Valley'), 
                 P1_name=c('John Doe', 'John Doe', 'John Doe', 'John Doe', 'Joe Blow'))

DF[, c('date', 'city', 'P1_name')] <- sapply(DF[, c('date', 'city', 'P1_name')], as.character)


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

  output$fdate<-renderUI({
    selectInput('dates', 'Select date', choices=DF[which(DF$P1_name == input$person), ]$date, selectize = FALSE)
  })

  output$map<-renderLeaflet({
    DF <- filter(DF, P1_name==input$person, date==input$dates)    
    output$city <-renderText({c("Location:", DF$city)})


    m <- leaflet() %>%
      addTiles() %>%  # Add default OpenStreetMap map tiles
      setView(lng=DF$lon, lat=DF$lat, zoom=5) %>%
      addMarkers(lng=DF$lon, lat=DF$lat, popup=DF$city)

  })

}

ui <- fluidPage(
  titlePanel("Testing Shiny"),
  sidebarLayout (
    sidebarPanel(

      selectInput('person', 'Select person', choices=unique(DF$P1_name), selectize = FALSE),

      radioButtons('radio', 'Select method', choices=c('show_date', 'no_date'), selected = NULL, inline = TRUE),
      conditionalPanel(
        condition = "input.radio == 'show_date'",
        uiOutput('fdate')

      ),

      textOutput("city")

    ),

    mainPanel(
      leafletOutput('map')
    )  
  ))

shinyApp(ui = ui, server = server)

      

+3


source to share


1 answer


Essentially, the output of $ fdate should be named with the same name as "dates"



library(shiny)
library(ggplot2)
library(dplyr)
library(leaflet)


DF <- data.frame(lon=c(-120.6596156, -87.27751, -119.7725868, -124.2026, -117.1858759),  
                 lat=c(35.2827524, 33.83122, 36.7468422, 41.75575, 34.5008311), 
                 date=c('2014-03-14', '2014-01-11', '2013-11-22', '2012-08-23', '2013-08-23'),
                 city=c('San Luis Obispo', 'Jasper', 'Fresno', 'Crescent City', 'Apple Valley'), 
                 P1_name=c('John Doe', 'John Doe', 'John Doe', 'John Doe', 'Joe Blow'))

DF[, c('date', 'city', 'P1_name')] <- sapply(DF[, c('date', 'city', 'P1_name')], as.character)


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

  output$dates<-renderUI({
    selectInput('dates', 'Select date', choices=DF[which(DF$P1_name == input$person), ]$date, selectize = FALSE)
  })

  output$map<-renderLeaflet({
    validate(
      need(!is.null(input$dates),""),
      need(!is.null(input$person),"")
    )
    DF <- filter(DF, P1_name==input$person, date==input$dates)    
    output$city <-renderText({c("Location:", DF$city)})


    m <- leaflet() %>%
      addTiles() %>%  # Add default OpenStreetMap map tiles
      setView(lng=DF$lon, lat=DF$lat, zoom=5) %>%
      addMarkers(lng=DF$lon, lat=DF$lat, popup=DF$city)

  })

}

ui <- fluidPage(
  titlePanel("Testing Shiny"),
  sidebarLayout (
    sidebarPanel(

      selectInput('person', 'Select person', choices=unique(DF$P1_name), selectize = FALSE),

      radioButtons('radio', 'Select method', choices=c('show_date', 'no_date'), selected = NULL, inline = TRUE),
      conditionalPanel(
        condition = "input.radio == 'show_date'",
        uiOutput('dates')

      ),

      textOutput("city")

    ),

    mainPanel(
      leafletOutput('map')
    )  
  ))

shinyApp(ui = ui, server = server)

      

+3


source







All Articles