I am struggling to use a reactive environment in a tabPanel environment in Shiny.
I want to use a reactive data file in a tabPanel environment in a inputPanel in Shiny. Here follows the code (I generate the data to use in C:/Temp below):
Data:
dir.create(file.path("C:","Temp"), showWarnings = FALSE)
write.csv(rbind("A","B","C","D"), "C:/Temp/A.csv",row.names = FALSE)
write.csv(rbind("A","B","C","D"), "C:/Temp/B.csv",row.names = FALSE)
write.csv(rbind("A","B","C","D"), "C:/Temp/C.csv",row.names = FALSE)
Shiny:
---
title: "Reactive in Tab environment"
output: html_document
runtime: shiny
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r , echo=FALSE}
navbarPage("Analysis",
tabPanel("File Choice",
inputPanel(
selectInput("File", label = "File Choice",
choices = c("A","B","C"), selected = c("A","B","C")[1])
),
Data <- reactive({read.csv(paste0("C:/Temp/",input$File,".csv"))})
),
tabPanel("File Show",
inputPanel(
selectInput("Choices", label = "Choices",
choices = Data()[,1], selected = Data()[,1][1])
)))
```
{r, echo = FALSE} navbarPage("Analysis", tabPanel("File Choice", inputPanel( selectInput("File", label = "File Choice", choices = c("A","B","C"), selected = c("A","B","C")[1])))) Data <- reactive({ read.csv(paste0("C:/Temp/",input$File,".csv")) }) navbarPage("Analysis2", tabPanel("File Show", inputPanel( selectInput("Choices", label = "Choices", choices = isolate(Data)[,1], selected = isolate(Data)[,1][1]) )))