Hello all,
I am getting an err- "Warning: Error in : MySQL server has gone away [2006]" or while saving data into a database-
My reprex-
library(shiny)
library(tidyverse)
iapply = pool::dbPool(drv = RMariaDB::MariaDB(), dbname = "dbname",
host = "11.111.111.11", port=3306,
user = "user", password = "password")
save<- pool::dbPool(drv = RMariaDB::MariaDB(), dbname = "dbname1",
host = "11.111.111.12", port=3306,
user = "user1", password = "password1")
ui <- fluidPage(
textInput("my_in","type a value for an entry"),
actionButton("newline_but","press for a new entry"),
tableOutput("showmytable")
)
server <- function(input, output, session) {
mydf <- reactiveVal(tibble(msg=NA_character_))
output$showmytable <- renderTable({
mydf()
})
observeEvent(input$my_in,{
local_df <- req(mydf())
curr_row <- nrow(local_df)
local_df[curr_row,1] <- input$my_in
mydf(local_df)
})
observeEvent(input$newline_but,{
local_df <- req(mydf())
mydf(add_row(local_df))
})
observeEvent(mydf(),
{
#export to a global but would be better to maybe write to a database
assign(x="new_file",
value=mydf(),
envir = .GlobalEnv)
})
iapply = pool::dbPool(drv = RMariaDB::MariaDB(), dbname = "dbname1",
host = "xx.xxxx.xx.xx", port=3306,
user = "user1", password = "password1")
observe({
if(mydf()!=")
{
dbWriteTable(save, value=new_file, name='dbname1', append=TRUE, row.names=FALSE ,
overwrite=FALSE)
}
})
}
shinyApp(ui, server)