Getting a shiny reactive variable to work in quotation marks

Hi, I'm a bit new to R and shiny so if I get any terms wrong, sorry in advance!

I've been having problems with trying to get a reactive variable to work, using shiny in a flexdashboard. I've been using the mcp package in r to try and do some changepoint analysis on the number of calls received weekly from a helpline. I've currently got a slider set up , which should change the location of the first changepoint. To put in priors, it seems I'd have to use something of the form cp_1 = "dnorm(input$cp1_loc1,10) T(MINX,MAXX)" but this doesn't work as including input$cp1_loc1 instead of a number seems to break it.

Is there a way to include the shiny reactive variable to work in the "" quotation marks? My code is:

allFMUdata <- read_csv("New_weeklyFMU.csv")
sliderInput("changepointy", "Max number of changepoints:",min = 1, max = 4, value = 1)
sliderInput("cp1_loc1", "Location of changepoint 1:", min = 1, max = 260, value = 200)
selectInput("model", label = "Type of model to model the FMU data:", choices = c("Varying", "Level"))
selectInput("model1", label = "Type of model to model the KN data:", choices = c("Level", "Varying"))

datf <- tibble(allFMUdata)
renderPlot({

  if (input$model == "Varying") {
    model = list(Calls ~ 1,~ 1 + Week)
  } else {
    model = list(Calls ~ 1,~ 1)
  }

  options(mc.cores = 3)
  set.seed(1) 
  
  cp1 = input$cp1_loc1
  
  if (input$changepointy == 1) {
    prior = list(
       cp_1 = "dnorm(cp1,10) T(MINX,MAXX)"
  )
  }

  fit = mcp(model, data = datf, prior = prior, family = poisson(), par_x = "Week")
  
  plot(fit)
})

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.