【问题标题】:Is it possible to use uiOutput in a conditionalPanel in Shiny?是否可以在 Shiny 的条件面板中使用 uiOutput?
【发布时间】:2015-10-28 15:51:04
【问题描述】:

我有一个非常基本的 Shiny 应用程序。

我正在使用renderUIuiOutput 来填充selectInput,可以在其中选择日期。

但我只希望在用户通过单选按钮选择选项时出现 selectInput

就目前而言,应用单选按钮没有任何作用。 (在这个阶段,如果一切正常,单击“无日期”将意味着没有绘制任何内容)。

我确定问题出在这里:

radioButtons('radio', 'Radio', choices=c('show_date', 'no_date'), selected = NULL, inline = FALSE),
  conditionalPanel(
    condition = "input.show_date == 'true'"
    uiOutput('fdate')
  ),

似乎无法在条件面板中使用uiOutput。为什么?

APP.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', 'Radio', choices=c('show_date', 'no_date'), selected = NULL, inline = FALSE),
      conditionalPanel(
        condition = "input.show_date == 'true'"
        uiOutput('fdate')

      ),

#       uiOutput('fdate'),
      textOutput("city")

    ),

    mainPanel(
      leafletOutput('map')
    )  
  ))

shinyApp(ui = ui, server = server)

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    试试

    condition = "input.radio == 'show_date'",
    

    改为

    【讨论】:

      猜你喜欢
      • 2021-11-05
      • 2021-11-05
      • 1970-01-01
      • 2016-08-14
      • 1970-01-01
      • 2018-11-29
      • 2015-07-07
      • 2016-06-04
      • 2020-06-03
      相关资源
      最近更新 更多