gpt4 book ai didi

r - 是否可以在 Shiny 的 conditionalPanel 中使用 uiOutput?

转载 作者:行者123 更新时间:2023-12-04 02:00:17 24 4
gpt4 key购买 nike

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

我正在使用 renderUIuiOutput 来填充可以选择日期的 selectInput

但如果用户通过单选按钮选择一个选项,我只希望 selectInput 出现:

enter image description here

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

我确定问题出在这里:

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)

最佳答案

尝试

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

反而

关于r - 是否可以在 Shiny 的 conditionalPanel 中使用 uiOutput?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31839815/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com