简体   繁体   中英

How to print different dataframes based of user input? Rmarkdown/Shiny

I am trying to have a user select a data frame and then have it be rendered as a table.

Here is the code I have.

---
title: "Untitled"
date: "2/24/2022"
output: html_document
runtime: shiny
---


```{r}


selectInput(inputId = "dataset",label = "Choose Data Frame", choices = c(mtcars, iris, cars))

renderTable({
    dataset <- get(input$dataset, choices = c(mtcars, iris, cars))
 })



```

Although for some reason the inputs are the column names of each dataset.

在此处输入图像描述

We may need choices as a vector of object names as string and then use get (assuming these objects are already created in the global env)

selectInput(inputId = "dataset",label = "Choose Data Frame",
    choices = c("mtcars", "iris", "cars"))

renderTable({
  dataset <- get(input$dataset)
})

-output

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM