I am trying to learn R Shiny in Rstudio. I have used the code below to define the use interface.
# Vamos a simular modelos poisson compuestos con diferentes
# distribuciones de severidad.
library(actuar)
library(shiny)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Número de simulaciones
headerPanel('Número de simulaciones'),
numericInput(inputId = "n",label = NULL,
value = 10,min = 1,max = 20000),
# Gráfica S exponencial.
headerPanel('Exponencial'),
sidebarPanel(
sliderInput(inputId = 'lambda1',label = 'Lambda 1',value = 7,
min = 0, max = 15),
sliderInput(inputId = 'rate',label = 'rate',value = 5,
min = 0, max = 15),
),
mainPanel(
plotOutput('plot1')
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
output$plot1 <- renderPlot({
#Preparativos para los gráficos:
set.seed(20)
n <- input$n
lambda1 <- input$lambda1
rate <- input$rate
S1 <- rcompound(n = n, #Genera n
model.freq = rpois(lambda1), #N~Poi(lambda1)
model.sev = rexp(rate = 2)) #Y~Exp(rate)
MASS::truehist(S1,
col=rainbow(125, start = 0.5, 1),
main = "exp",nbins = 125)
abline(h=0,v=0,col="black",lwd=2)
})
}
# Run the application
shinyApp(ui = ui, server = server)
In the server function, it is always throwing me an error telling lamda not found. So I tried to define lamda as shown below: