Hello. I am working on my first shiny app where I would like to have multiple sliders to control parameters to my main function. My plot is not updating when I change any of the sliders. Any help would be great. Thank you.
ui <- fluidPage(titlePanel("Effects of Tick to Carrier Interaction on Human CCHF Cases Per Year"),
sliderInput("betaTC","Tick to Carrier Contact", min=0, max=1, step=0.1, value=0),
sliderInput("betaCT", "Carrier to Tick Contact", min=0, max=1, step=0.1, value=0),
sliderInput("betaHH", "Human to Human Contact", min=0, max=1, step=0.1, value=0),
#DT::dataTableOutput("data"),
plotOutput("plotIH"))
server <- function(input, output, session){
# time to start solution
timeCombined = seq(from = 0, to = 365, by = 0.1)
#initialize initial conditions
initialXCombined = c(SH = 82000, EH = 0, IH = 1, RH = 0, ST = 870000, ET = 0, IT = 107010, SC = 145000, EC = 0, IC = 35, RC = 0)
defaultParams <- c(betaHH = .0001,
betaTH = .000018,
betaCH = .001,
betaTC = .001, # One tick attaches to one carrier per year
betaCT = 59/365, # One cattle infects 59 ticks per year (assuming 60 ticks on cattle)
betaTTV = 0.0001, # ticks not giving birth
betaTTH = 59/365,
gamma = 1/10, # death occurs 7-9th day after onset of illness plus 2 day incubation
muH = (1/(365 * 79)),
muT = (1/(365* 2)) + 0.0035,
muC = (1/(8 * 365)), #sheep/deer live 6-11 years
piH = 1.25/(79 * 365), # one couple produces 2.5 children in a lifetime, so one mother produces 1.25
piT = 0.00001, # ticks not giving birth
piC = 3/(8 * 365), # sheep produce 7 babies in their life
deltaH1 = 1/2.5, # 1-3 days from ticks, 5-6 days from blood contact
deltaT = 1/1.5,
deltaC = 1/2,
alpha = 1/17, # recovery after 15 days
alpha2 = 1/7)
dataSetCombined <- eventReactive(defaultParams,{
ode(y = initialXCombined,
times = timeCombined,
func = CCHFModelCombined,
parms = defaultParams,
sliderValue1 = input$betaTC,
sliderValue2 = input$betaCT,
sliderValue3 = input$betaHH,
method = "ode45"
) %>%
as.data.frame() -> out
})
output$data <- DT::renderDataTable({
dataSetCombined()
})
output$plotIH <- renderPlot({
ggplot(dataSetCombined(), aes(x=time , y = IH)) +
geom_line(color = '#00CED1', size = 1) +
ggtitle("Crimean-Congo haemorrhagic fever") +
scale_x_continuous(name = "Time(days)") +
scale_y_continuous(name = "Infected Humans", limits = c(0,50))
})
}
shinyApp(ui = ui, server = server)
This is the beginning of my function to show how I use the slider values.
CCHFModelCombined = function(t,x,params, sliderValue1, sliderValue2, sliderValue3)
{
SH <- x[1]
EH <- x[2]
IH <- x[3]
RH <- x[4]
ST <- x[5]
ET <- x[6]
IT <- x[7]
SC <- x[8]
EC <- x[9]
IC <- x[10]
RC <- x[11]
if(t <= 91){
params <- c(betaHH = sliderValue3,
betaTH = 0.000000001,
betaCH = 0.0000000001,
betaTC = sliderValue1,
betaCT = sliderValue2,
betaTTV = 0.0000000001,
betaTTH = 1/36500000,
gamma = 1/10,
muH = (1/(365 * 79)),
muT = (25/(365* 2)),
muC = (1/(8 * 365)),
piH = 1.25/(79 * 365),
piT = 1/36000000,
piC = 7/(8 * 365),
deltaH1 = 1/2.5,
deltaT = 1/1.5,
deltaC = 1/2,
alpha = 1/17,
alpha2 = 1/7) }