Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

R Shiny can be utilized to generate buttons that execute mysql code by utilizing the RMySQL package. Below is an example code snippet that shows how this can be done:

  1. Install the RMySQL package:
install.packages("RMySQL")
  1. Load the library:
library(RMySQL)
  1. Establish a connection with the mysql database:
con <- dbConnect(MySQL(),user='username',password='password',dbname='database_name',host='host_name')

Replace username, password, databasename and hostname with the relevant credentials.

  1. Define the code you want to execute:
query <- "SELECT * FROM table_name"

Replace table_name with the name of your table.

  1. Create a button that will execute the query:
actionButton("execute_query", "Execute Query")
  1. Define an observer that will execute the query when the button is clicked:
observeEvent(input$execute_query,{
    data <- dbGetQuery(con,query)
    #Do something with the data returned by the query
})
  1. Disconnect from the mysql database:
onStop(dbDisconnect(con))

These steps can be repeated with different queries and buttons to execute several mysql commands via R Shiny.