在Shiny数据库中更新后进行文本更新

时间:2018-08-27 20:44:59

标签: shiny shinydashboard shiny-reactivity

我正在为此应用程序使用ShinydashboardPlus。我试图在数据库中更新后立即更新值。我可以检查数据库中是否已更新。但是刷新或单击“编辑”图标按钮后,我可以看到更改。我已经尝试了两种方式的watchvent和eventreactive.BUT有人可以指导我怎么做吗?谢谢。

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()

  })

}

0 个答案:

没有答案