Problem to upload form responses in Shiny to a MySQL database

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="admin", password="Nikogta4", 
                            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:

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

first of all, I would recommend not doing anything in shiny that you can't yet do comfortably in an R script.
your paste statement result looks like this
(assuming basesSMI has some text like "something")

"INSERT INTO `something`.`ICD_34618ICD_34618` values ((3.4.1.6A) Avance)"

I think this isnt valid SQL. What are you trying to do ? when you call writingMarks you are using an undeclared ICD_34618 object to pass in as a param, (which wont work..) ? but you dont make use of it withing the function body, you have some repeated strings of it.

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.