【问题标题】:Accessing Dynamic Data from Drop down box in Shiny从 Shiny 的下拉框中访问动态数据
【发布时间】:2017-06-28 17:36:05
【问题描述】:

我正在创建一个闪亮的仪表板,其中我需要根据下拉框中的选项动态更新信息。

我的问题是 1. 这可以做到吗?如果可以:怎么做?

我已经创建了我的下拉菜单,它工作正常,从那里我想按照“如果选择了出口 xyz,使用唯一信息更新图表”的方式来做同样的事情

到目前为止的代码:

output$Box1 = renderUI(
selectInput("Outlets",
"Select an Outlet",
 c("Start Typing Outlet 
Name",as.character(unique(outlets$Outlets))),
"selectoutlet"))

一旦选择了出口,我希望我的 R 脚本中的数据只更新那个出口。

【问题讨论】:

    标签: rstudio shinydashboard


    【解决方案1】:

    由于您没有提供可重现的示例,这里是带有mtcars 数据集的代码:

     library(shiny)
    library(dplyr)
    library(ggplot2)
    
    ui= fluidPage(
      sidebarLayout(
        sidebarPanel(
          selectInput(inputId= "cyl", label= "cyl", 
                         choices= unique(mtcars$cyl), 
                         selected= sort(unique(mtcars$cyl))[1],
                         multiple=F)
        ),
        mainPanel(
          plotOutput("plot")
        )
      )
    )
    
    server= function(input, output,session) {
    
      df_filtered <-reactive({
        data <- mtcars %>%  {if (is.null(input$cyl)) . else filter(., cyl %in% input$cyl)} # here is the reactive dataset which You can further use it in table or in the plot
        print(data)
        data
      }) 
    
      output$plot <- renderPlot({
        ggplot(data = df_filtered(), aes(x=cyl,y=mpg)) + geom_point(size=5) # as You can see i have used data = df_filtered()
    })
    }
    
    shinyApp(ui, server)
    

    查看代码中的 cmets 以更好地了解其工作原理。

    【讨论】:

      猜你喜欢
      • 2016-05-25
      • 2020-01-06
      • 2015-06-22
      • 1970-01-01
      • 2019-06-12
      • 2017-05-30
      • 2019-06-25
      • 2013-05-31
      • 2013-01-25
      相关资源
      最近更新 更多