r - 在 r shiny 中组合两个选择框值
问题描述
我需要在 R Shiny 中组合两个选择框值。选择框 1 有年份,选择框 2 有月份。
如果用户选择 2018 和 06,我应该将 2018-06 放入变量中。
我试过paste(input$year,input$month,sep="-")
但它不起作用。
解决方案
这应该可以,请注意我从 更改reative
为reactiveValues
因为我认为这对您来说应该更直观,您可以使用v$value
which 将包含您想要的内容。我建议您阅读https://shiny.rstudio.com/articles/reactivity-overview.html以便您更好地了解正在发生的事情
library(shiny)
ui <- fluidPage(
textOutput("value"),
selectInput("year","year",choices = c(2017,2018),selected = 1),
selectInput("month","month",choices = c(1:12),selected = 1)
)
server <- function( session,input, output) {
v <- reactiveValues(value=NULL)
observe({
year <- input$year
month <- input$month
if(nchar(month)==1){
month <- paste0("0",month)
}
v$value <- paste(year,month,sep="-")
})
output$value <- renderText({
v$value
})
}
shinyApp(ui, server)
推荐阅读
- java - 使用 jdb 调试 Java servlet。如何将 jdb 与 Tomcat 连接
- java - 如何从底页导航到活动
- python - Python中的文本文件行计数器返回错误的行数
- cookies - 如果 cookie 策略需要选择加入,UTM 是否可以存储在 cookie 中以进行归属?
- bash - 如何在 BASH 中将多个文件插入到单个 ext 程序中
- sql - 在某些日期缺少数据时聚合数据的问题
- python - 将查询结果保存在变量上
- python - 有没有办法用单个值和元组从列表中标记图表中的多个点?
- email - 尝试使用 Office 365 帐户通过 smtp 发送邮件时出错
- swift - 协议覆盖的 Presenter 层