rchess icon indicating copy to clipboard operation
rchess copied to clipboard

Input moves via shiny?

Open McCartneyAC opened this issue 7 years ago • 2 comments
trafficstars

Hi! I love that you've made and kept up this package. I'm trying to build a shiny app and I'm having a hell of a time getting user-input moves to register via your example code, e.g. chss$move("f4") . The typical error I'm getting is : Error:attempt to apply non-function because it's treating the chss environment as, well, an environment and so calling chss$mov() isn't a function that can be embedded within a reactive wrapper. Does that make sense?

I'm trying to implement this code:

ui = shinyUI(
  fluidPage(
      # chessboardjsOutput('board', width = 300), 
      textInput("mv", "Input Your Move", placeholder = "Move"),
      actionButton("make_move", label = "Move", icon = icon("chess")),
      tags$p("Available Moves"),
      textOutput(outputId = "avail"), 
      tags$p("Move History"),
      tableOutput(outputId = "hist"),
      tags$p("Turn:", textOutput(outputId = "turn_is"))
      )
    )
  

server = function(input, output, session) {
  
  chss <- Chess$new()
  chss<-observeEvent(input$make_move, {
    chss$move(quote(mv)) 
  }, 
  ignoreNULL = T)
  # output$board <- renderChessboardjs({
  #   chessboardjs()
  # })
  output$avail<-reactive({
    chss$moves()
  })
  output$turn_is<-reactive({
    chss$turn()
  })
  output$hist<-reactive({
    chss$history(verbose=T)
  })
   

  
}

shinyApp(ui = ui, server = server)

McCartneyAC avatar Jul 02 '18 23:07 McCartneyAC

Hello @McCartneyAC, were you able to figure this out? Thank you.

R-icntay avatar Jun 07 '22 22:06 R-icntay

No, I gave up on the project and forgot I ever posted this error. I think the issue is that the rchess package stores information about the game as an object and I'm not great at OOP (which is why I like R and Shiny in the first place!)

if you make progress on it, let me know.

McCartneyAC avatar Jun 08 '22 15:06 McCartneyAC