Unable to update description in shinydashboardplus boxprofileitem after database update

I am using ShinydashboardPlus for this APP. I am trying to update the value as soon as I am updating in the database. I can check that it is updated in database.but after refreshing or clicking the edit icon button I can see the changes. I have tried observevent and eventreactive in both way.BUt can anybody guide me how to do it? Thanks is advance.


ui.R
library(shiny)
library(shinyalert)
library(shinydashboardPlus)
library(shinydashboard)

dashboardPagePlus(

  header = dashboardHeaderPlus(
    title = "IEIS",
    enable_rightsidebar = FALSE

  ),
  sidebar = dashboardSidebar(
    sidebarMenu(
      menuItem("Personal Info", tabName = "p_info", icon = icon("user", lib = "glyphicon"))
    )
  ),
  body = dashboardBody(
    tabItems(
      tabItem(tabName = "p_info",
              fluidRow(
                uiOutput("long_info")

              )

      )
    )
  ),
  rightsidebar = rightSidebar(),
  title = "Demo"
) 
#########################
server.r
 library(shiny)
library(shinyalert)
library(shinydashboardPlus)
library(shinydashboard)
library(RMySQL)


function(input, output, session) {

  eis_data_con<-dbConnect(RMySQL::MySQL(),user='root',password='XXXXXXXX',dbname='eis',port=3306)
  user_details<<-"123456"

  long_info_data<-reactive({
      qr<-paste0("Select name from user_details where id='",user_details,"'")
      user_long_data<<-dbGetQuery(eis_data_con,qr)
  })

  output$long_info<-renderUI({
    long_info_data()
    box(
      title = "Detailed Profile:",
      width = 4,
      boxProfile(
        boxProfileItemList(
          bordered = TRUE,
          #name

          fluidRow(
            column(10,
                   boxProfileItem(
                     title = "Name",
                     description =user_long_data$name
                   )
            ),
            actionButton("name_edit", "", icon = icon("edit"))
          )
        )
      )
    )
  })

  name_edit_modal<-function()
  {
    modalDialog(
      title = "Name",
      textInput("edited_name","Enter Your Changed Name",value = user_long_data$name),
      easyClose = FALSE,
      fade = TRUE,
      footer = tagList(
        modalButton("Cancel"),
        actionButton("edit_name_save", "Save", icon = icon("save"))
      ),
      size='s')
  }

  observeEvent(input$name_edit,{
    #shinyalert('Name Edit', type='input', inputValue = user_long_data$name)
    showModal(
      name_edit_modal()
    )
  })

  observeEvent(input$edit_name_save,{
    qr<-paste0("update user_details set name='",input$edited_name,"' where id='",user_details,"'")

    res<-dbSendStatement(eis_data_con,qr)
    removeModal()

  })

}

I think you need to use reactivePoll function to invalidate or not the data based on your DB update. Basically, query the database every X seconds, using a small check request (i.e last modification date) with the checkFunc function, and if it has changed, reactivePoll rerun valueFunc and return results.

See :

With this, your app will be able to know when database has been updated.

1 Like