RL_Pug
RL_Pug

Reputation: 887

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.

enter image description here

Upvotes: 2

Views: 131

Answers (1)

akrun
akrun

Reputation: 887951

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

enter image description here

Upvotes: 1

Related Questions