I'm relatively new to R, and I'm trying to build a Shiny app that determines the Nash Equilibria of a game from an n x n matrix. Ideally, I'm trying to make it so that the player puts the players' payoffs in the matrix in a,b format (Player 1's playoffs being a, Player 2's being b) and then plug their inputs into the sim_nasheq command from the "Recon" package to solve for any pure or mixed equilibria.
Basically, the problem I'm having is figuring out how to store the values the user inputs so I can call them back into the script later on. I imagined I'd make an object of each player's payoffs, but I'm struggling to figure out how to tell R to store those values.
This is the code I have so far. It's a pretty rough sketch so far, but I'm trying to work through it piece by piece.
##install.packages("shiny") ##install.packages("shinyMatrix") ##install.packages("Recon") library(shiny) library(shinyMatrix) library(Recon) if (interactive()) { #ui ui <- fluidPage( selectInput('NumGrid',label = 'Number of Columns', choices = c(2:10),selected = 5), selectInput('NumGrid2',label = 'Number of Rows', choices = c(2:10),selected = 5), actionButton("create", "Create"), conditionalPanel(condition = "input.create > 0", uiOutput("grid")) ) #server server <- function(input, output, session) { # need to add something here to solve for nash. Try command "sim_nasheq" # adding Matrix observe({ if (!is.null(input$create)) { m = reactive({matrix('',ncol = as.numeric(input$NumGrid) ,nrow = as.numeric(input$NumGrid2))}) output$grid <- renderUI({ div( matrixInput(inputId = "newGrid", value = m()), actionButton("solve", "Solve") ) }) } }) } shinyApp(ui, server) }
I'm sorry ahead of time if this has a really simple answer that I'm just completely missing. Like I said, I'm pretty new to R and coding in general, but I really appreciate the help.
https://stackoverflow.com/questions/67378634/need-help-recalling-matrix-inputs-to-formulate-output May 04, 2021 at 12:01PM
没有评论:
发表评论