I have shiny app which will give me 6 plot and if i want download the plot or data used to plot on csv. I wanted to a run button which will start the process of all six plots. Is it possible to do that? I checked about multiple outputs with a single action button. It was not very clear to me. I would also like to have clear action button which will clear all the inputs and outputs.
library(shiny)
library(shinydashboard)
ui <- dashboardPage(dashboardHeader(title = "IDF"),
dashboardSidebar(
sidebarMenu(
menuItem("Data", tabName = "dataimport"),
menuItem("Stationary IDF", tabName = "Stidf"),
menuItem("Non-stationary IDF", tabName = "NStidf"),
menuItem("IDF under climate change", tabName = "Gcmidf"))),
dashboardBody(
tabItems(
tabItem(tabName = "dataimport",
fileInput("file","Hourly precipitation data(.csv format)",accept = ".csv"),
checkboxInput("header", "Header", TRUE),
radioButtons('UserCov',"Mention if there is a local covariate to be added, if Yes add the file",
choices = list("No" = 1,"Yes" = 2), inline = T),
fileInput("cov","Local covariate data(.csv format)",accept = ".csv"),
checkboxInput("head", "Header", TRUE),
numericInput("lat","Latitude", value = c()),
numericInput("lon","Longitude", value = c()),
radioButtons('gcm', "Select the GCM", choices = list("MPI" = 1,"MRI" = 2,"CNRM"=3,"EC" =4,"MIR"=5), inline = T),
sliderInput("fut", label = h4("Select the starting point of time period"),min = 2015, max = 2100, value = 2020)),
tabItem(tabName = "Stidf",plotOutput('SIDF')),
tabItem(tabName = "NStidf",plotOutput('NIDF')),
tabItem(tabName = "Gcmidf",
tabsetPanel(type = "tabs",
tabPanel("s1",plotOutput('plot1')),
tabPanel("s2",plotOutput('plot2')),
tabPanel("s3",plotOutput('plot3')),
tabPanel("s5", plotOutput('plot4'))))
)))
server <- function(input, output,session) {
output$SIDF <- renderPlot({
req(plotSt())
print(plotinput(plotSt()))
})
output$NIDF <- renderPlot({
req(plotNSt())
print(plotinput(plotNSt()))
})
output$plot1 <- renderPlot({
req(PCC1())
print(plotinput(PCC1()))
})
output$plot2 <- renderPlot({
req(PCC2())
print(plotinput(PCC2()))
})
output$plot3 <- renderPlot({
req(PCC3())
print(plotinput(PCC3()))
})
output$plot4 <- renderPlot({
req(PCC4())
print(plotinput(PCC4()))
})
}
shinyApp(ui, server)
This is my plot function
plotinput <- function(P){
PG <- as.matrix(P)
A = PG[1,]; B = PG[2,]; C = PG[3,]
Z = matrix(0,LDR,LRP)
for (j in 1:LRP) {
for (i in 1:LDR) {
if (C[i] != 0) {
Z[i,j] = A[i] +((B[i]/C[i])*(((-log(1-(1/RP[j])))^-C[i])-1))
} else {
Z[i,j] = A[i] +((B[i])*(-log(-log(1-(1/RP[j])))))
}
}
}
col_set <- rainbow(nrow(Z))
matplot(Z,type = "o", lty = "solid",
lwd = 2, xlab = "Duration (hr)",ylab = "Intensity (mm/hr)",
col = col_set, cex.lab = 1.5, cex.axis=1.5,
cex.main=1.5, cex.sub=1.5, pch = 21, xaxt='n')
}
I would really appreciate any help.