Hi!! Below I attach an example. Thanks for your help. I really appreciate it.
library(shiny)
library(fitdistrplus)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
selectInput(inputId = "selectVar", label = "Select variable",
choices = c("var1", "var2")),
checkboxInput(inputId = "bootstrap", label = "Perform bootstrap", value = F),
conditionalPanel(condition = "input.bootstrap == true",
sliderInput(inputId = "slider1", label = "Select sample size for bootstrap",
min = 1000, max = 50000, value = 5000, step = 1000 )),
radioButtons(inputId = "radioB1", label = "Select the type of file", choices = list("png", "pdf")),
actionButton(inputId = "boton1", label = "Make plot")
),
mainPanel(
br(),
tabPanel(title = "tab1",
plotOutput(outputId = "CyF") %>% withSpinner(type = getOption("spinner.type",
default = 4), hide.ui = T)),
downloadButton(outputId = "download1", label = "Download plot")
#withSpinner(plotOutput(outputId = "CyF"),
# type = getOption("spinner.type", default = 4), hide.ui = T))
)
)
)
server <- function(input, output, session) {
data <- eventReactive(input$boton1, {
var1 <- rnorm(1000, 0, 1)
var2 <- rnorm(1000,10,5)
cbind(var1, var2)
})
cyf_plot <- reactive({
if(isolate(input$bootstrap==F)){
descdist(data()[,isolate(input$selectVar)])
} else {
descdist(data()[,isolate(input$selectVar)], boot = isolate(input$slider1))
}
})
output$CyF <- renderPlot({
cyf_plot()
})
#DownloadHandler para guardar el gráfico
output$download1 <- downloadHandler(
filename = function() {
paste("gráfico_CyF", input$radioB1, sep = ".")
},
content = function(file) {
if(input$radioB1 == "png")
png(file)
else pdf(file)
cyf_plot()
dev.off()
}
)
}
shinyApp(ui = ui, server = server)