I have an R application Shinythat calculates several statistics in different tables. Since the calculations are quite intense, I use submitButtonto prevent reactivity. My problem is that each calculation (all in different tables) writes the outputs to a folder, and I want to Shinywrite the output for all tables during initialization. Unfortunately, it Shinycreates only tab output, which is active during initialization. Is there any way to say Shinythat it should calculate / output the output for each tab during initialization?
Here is an example provided in Shiny[Tutorial] :( http: //www.http: //rstudio.imtqy.com/shiny/tutorial/#more-widgets/ )
ui.R:
library(shiny)
shinyUI(pageWithSidebar(
headerPanel("More Widgets"),
sidebarPanel(
selectInput("dataset", "Choose a dataset:",
choices = c("rock", "pressure", "cars")),
numericInput("obs", "Number of observations to view:", 10),
helpText("Note: while the data view will show only the specified",
"number of observations, the summary will still be based",
"on the full dataset."),
submitButton("Update View")
),
mainPanel(
tabsetPanel(
tabPanel("Summary", verbatimTextOutput("summary")),
tabPanel("Table", tableOutput("view"))
)
)
))
server.R:
library(shiny)
library(datasets)
shinyServer(function(input, output) {
datasetInput <- reactive({
switch(input$dataset,
"rock" = rock,
"pressure" = pressure,
"cars" = cars)
})
output$summary <- renderPrint({
dataset <- datasetInput()
capture.output(summary(dataset),file="summary.txt")
})
output$view <- renderTable({
a<-head(datasetInput(), n = input$obs)
capture.output(a,file="table.txt")
})
})
source
share