【问题标题】:Selected value not shown using renderUI未使用 renderUI 显示所选值
【发布时间】:2017-05-03 17:20:54
【问题描述】:

我正在尝试开发一个带有*Input() 函数的闪亮应用程序,其输出取决于服务器中计算的一些结果。您可以在下面找到示例代码:

library(shiny)
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(
    sliderInput("mpg", "Mpg", min(mtcars$mpg), max(mtcars$mpg), 
                c(min(mtcars$mpg), max(mtcars$mpg)), ticks = FALSE, step = 1),
    uiOutput("cyl")
  ),
  dashboardBody(
    tableOutput("out")
  )
)


server <- function(input, output) {

  data_filtered_by_mpg <- reactive({
    filter(mtcars, mpg >= min(input$mpg),
           mpg <= max(input$mpg))
  })

  output$cyl <- renderUI({
    selectInput("cyl", "Cyl", choices = data_filtered_by_mpg()$cyl, 
                selected = data_filtered_by_mpg()$cyl[1])
  })

  output$out <- renderTable(data_filtered_by_mpg())

}

shinyApp(ui, server)

这里的问题是选择列表的选定输入不是data_filtered_by_mpg()$cyl向量的第一个元素而是""。你有什么建议吗?

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    这可能是由于重复。因此尝试使用独特的价值。

      output$cyl <- renderUI({
        cyl <- unique(data_filtered_by_mpg()$cyl)
        selectInput("cyl", "Cyl", choices = cyl, 
                    selected = cyl[1])
      })
    

    【讨论】:

    • 如果它满足您的要求,我将不胜感激:)
    猜你喜欢
    • 1970-01-01
    • 2017-12-21
    • 2022-01-16
    • 1970-01-01
    • 2017-08-18
    • 2021-01-25
    • 1970-01-01
    • 1970-01-01
    • 2021-10-26
    相关资源
    最近更新 更多