I know this question has come up a few times e.g. Markov Model diagram directly from data (makovchain or deemod package?). I attempted to implement remedies based on those solutions, but this is still not working. Clearly, I am missing something and would be grateful for any assistance!
In short, I am trying to supply state_names to heemod::define_transition within a Shiny app.
Here is my code:
library(heemod)
library(diagram)
library(shiny)
ui=shinyUI(fluidPage(
titlePanel("Markov Diagram Creator"),
fluidRow(
sidebarPanel(
textAreaInput("statenames_1",label = "Enter state names here...", value = "H,S1,S2,D"),
actionButton("go","Go")
),
mainPanel(
hr(),
plotOutput("plot")
)
)))
server=function(input,output){
state_names <- reactive( {
unlist(strsplit(x=input$statenames_1,split = "[[:punct:]]"))
})
len_states <- reactive({length(state_names())})
states <- reactive({state_names()})
statenames <- reactive({list(states(), states())})
markovTransitionMatrix <- reactive({matrix(0.25, nrow = len_states(), ncol = len_states(), dimnames = statenames())})
lis <- reactive({ as.list( markovTransitionMatrix() ) })
lis()$state_names <- reactive({ statenames() }) # Error in lis() <- reactive({ : invalid (NULL) left side of assignment
output$plot <- renderPlot({
plot(do.call( define_transition, lis() ), cex=0.75, ylim = c(0,.4))
})
}
shinyApp(ui,server)