rchess
rchess copied to clipboard
Input moves via shiny?
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)
Hello @McCartneyAC, were you able to figure this out? Thank you.
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.