【问题标题】:How to dynamically select dataframe in Rshiny如何在 R Shiny 中动态选择数据框
【发布时间】:2022-01-02 05:02:54
【问题描述】:

我想在 Rshiny 中动态选择数据框。

这就是我所拥有的:

## First we are going to import some example dataframes
Biomarker <- read_excel("C:\\Datasets\\Example1.xlsx")
Baseline <- read_excel("C:\\Datasets\\Example2.xlsx")
Mutation <- read_excel("C:\\Datasets\\Example3.xlsx")

# We are going to create a list of this dataframes so we can select which one we want in the Rshiny app
ldf <- list(Biomarker = Biomarker, Baseline = Baseline, Mutation = Mutation)

ui <- fluidPage(
  selectInput("dataset", label = "Dataset", ldf),
  verbatimTextOutput("summary"),
  tableOutput("table")
)

但这实际上允许您选择数据框内的行,而不是数据框本身。

有什么想法吗?

【问题讨论】:

    标签: r dataframe shiny


    【解决方案1】:

    我没有您的数据并且您缺少服务器端,所以我不确定您的代码出了什么问题。但是,在 renderTable 中更改数据帧的一个非常简单的方法就是根据 selectInput 中的选择使用 if else 语句,如下所示:

    library(shiny)
    
    ui <- fluidPage(
      selectInput("dataset", label = "Dataset", choices = c("mtcars", "starwars", "iris")),
      tableOutput("table")
    )
    
    server <- function(input, output, session) {
      output$table<-renderTable({
       if(input$dataset == "mtcars") {
          mtcars
        } else if (input$dataset == "starwars") {
          starwars[1:5]
        } else if (input$dataset == "iris") {
          iris
        }
        
      })
      
    }
    
    shinyApp(ui, server)
    

    【讨论】:

      猜你喜欢
      • 2017-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-27
      • 2019-06-14
      • 1970-01-01
      • 2021-01-27
      • 2016-12-21
      相关资源
      最近更新 更多