0

Hello and thanks for reading me. I am a bit desperate, since I am trying to make an app in shiny in which I can make a form and that the responses are saved within a MySQL database hosted on AWS. I've been doing some research and came across some code about it, but so far I haven't gotten it to work properly and I'm not sure what the problem is. Anyone have any ideas? I wish they could help me

The code that I have so far is the following:

library(shiny)
ui.R <- shinyUI(
  fluidPage(
    fluidRow(
      column(2,selectInput("task1", label=NULL,
                           choices = c(0:5), 
                           selected = 0))
    ),
    actionButton("uploadMarks","Botonejemplo")
  )
)

library(shiny)
library(RMySQL)
Sys.setlocale(category = "LC_ALL", locale = "Mexico")



server.R<-shinyServer( ##here
  function(input,output,session){
    observe({
      # Take a dependency on input$uploadMarks
      if(input$uploadMarks==0) return()
      
      #Use isolate() to avoid dependency on input$task1
      isolate({
        current_selection<-input$task1
        writingMarks("basesSMI",ICD_34618,"test")
      })#iso
    }
    )
  }
)


runApp(list(
  ui={ ui.R},
  server =  {
    # function to connect to MySQL database and sending query of INSERT
    writingMarks <- function(basesSMI,ICD_34618,valueToInsert){
      courseDB <- dbConnect(MySQL(), user="example", password="example", 
                            host="smi-economia.c9w9kj4apfml.us-east-2.rds.amazonaws.com", db=basesSMI)
      query <- paste("INSERT INTO `",basesSMI,"`.`ICD_34618","ICD_34618",
                     "` values (","(3.4.1.6A) Avance",")",sep="")
      dbSendQuery(conn=courseDB, query)
      connections <- dbListConnections(MySQL())
      for(i in connections) {dbDisconnect(i)}
    }
    server.R
  }
))

And I am having the following error when running the app:

Warning: Error in .local: could not run statement: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.1.6A) Avance)' at line 1
  60: .local
  59: dbSendQuery
  57: writingMarks [#10]
  44: <observer> [#8]
   1: runApp

Additionally, I have attached a screenshot of how the database looks in MySQL, maybe it could be useful:

ScreenShot of MySQL table

Thanks for reading me. hopefully someone can support me in this regard

0 Answers0