I have an Excel file with several tabs. How can I run my shiny App looping through the tabs -- using one tab (one at a time) as input?
Here is a simple example. In reality, raw_input
is the Excel file with 3 tabs. In this code, out3() will only be run for tab1.
Final outcome I am looking for is Output.csv with 3 tabs:
- Tab1 is out3() calculated using tab1
- Tab2 is out3() calculated using tab2
- Tab3 is out3() calculated using tab3
library(shiny)
ui <- fluidPage(
shiny::downloadButton('download_button', "Save")
)
server <- function(input, output, session) {
raw_input <- reactive({
df <- data.frame(tab1 = c(1, 2, 3),
tab2 = c(4, 5, 6),
tab3 = c(1, 1, 1)
})
# IN THIS EXAMPLE BELOW, IT ONLY RUNS FOR THE 1ST TAB
# I NEED TO RUN IT FOR EACH TAB
out1 <- reactive({
return(raw_input()[[1]]**2)
})
out2 <- reactive({
return(out1() * 5)
})
out3 <- reactive({
return(out1()+out2())
})
output$download_button <- shiny::downloadHandler(
filename = function() {paste("Output.csv")},
content = function(file) {
write.csv(out3(), file)
}
)
}
shinyApp(ui, server)