Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 立即重新单击按钮无效_R_Shiny - Fatal编程技术网

R 立即重新单击按钮无效

R 立即重新单击按钮无效,r,shiny,R,Shiny,我有一个闪亮的应用程序,允许用户通过点击表格中的按钮来编辑记录笔记。它适用于第一次单击,但在关闭编辑对话框(确定或取消)后,同一按钮立即变为innert。如果单击第二个按钮,第一个按钮将再次激活。你知道怎么解决这个问题吗 require(shiny) require(DT) require(tidyverse) states_dat = tibble(id = state.abb, name = state.name, pop = state.x77[,1], note = NA_charac

我有一个闪亮的应用程序,允许用户通过点击表格中的按钮来编辑记录笔记。它适用于第一次单击,但在关闭编辑对话框(确定或取消)后,同一按钮立即变为innert。如果单击第二个按钮,第一个按钮将再次激活。你知道怎么解决这个问题吗

require(shiny)
require(DT)
require(tidyverse)

states_dat = tibble(id = state.abb, name = state.name, pop = state.x77[,1], note = NA_character_)

#------------------------------------------------

# Return the UI for a modal dialog with state update options
editModal = function(conv_id) {
  ns = NS('state-update')
  curr_mon_id <<- conv_id
  
  conv = dplyr::filter(my_dt$df, id == conv_id$id)
  modalDialog(
    h3(paste0('Edit note ', conv_id)),
    textInput(ns("edit_note"), "Note", value = conv$note, width='600px'),
    footer = tagList(
      modalButton("Cancel"),
      actionButton(ns("ok"), "OK")
    )
  )
}

#------------------------------------------------

# Main screen server
dt_server = function(input, output, session) {
  ns = session$ns
  myValue = reactiveValues(check = '')
  
  shinyInput = function(FUN, len, id, ns, ...) {
    inputs = character(len)
    for (i in seq_len(len)) inputs[i] = as.character(FUN(paste0(id, i), ...))
    inputs
  }
  
  my_dt <<- reactiveValues(df = {
    dat = states_dat
    dat$` ` = shinyInput(actionButton, nrow(dat), 'button_', label = "Edit note",
                         onclick = glue::glue('Shiny.onInputChange("{ns("select_button")}", this.id)'))
    dat
  })
  
  observeEvent(input$select_button, {
    selectedRow = as.numeric(strsplit(input$select_button, "_")[[1]][2])
    myValue$check <<- my_dt$df[selectedRow,1]
    showModal(editModal(myValue$check))
  })
  
  output$states_table = DT::renderDT(filter = "top", {
    return(my_dt$df)
  }, escape = FALSE)
}

#------------------------------------------------

# Record Update server
mud_server = function(input, output, session) {
  ns = session$ns
  
  # When OK button is pressed, check if details have changed and if so update postgres db
  observeEvent(input$ok, {
    id = curr_mon_id$id[1]
    
    if(!identical(input$edit_note, states_dat$note[states_dat$id == id])){
      my_dt$df$note[my_dt$df$id == id] = input$edit_note
    }
    
    removeModal()
  })
}

#------------------------------------------------

# Data table UI
dt_ui = function(id){
  ns = NS(id)
  
  tagList(
    titlePanel( h3('State populations'), windowTitle = 'States-Pop'), hr(),
    mainPanel(width=12, DT::DTOutput(ns("states_table"))
    )
  )
}

#------------------------------------------------

ui = fluidPage( dt_ui(id = "states-manager"))

server = function(input, output, session) {
  callModule(module = dt_server , id = "states-manager")
  callModule(module = mud_server , id = "state-update")
}

shinyApp(ui = ui, server = server)
require(闪亮)
需要(DT)
要求(整洁的人)
states\u dat=tibble(id=state.abb,name=state.name,pop=state.x77[,1],note=NA\u character\ux)
#------------------------------------------------
#返回带有状态更新选项的模式对话框的UI
editModal=函数(conv_id){
ns=ns(‘状态更新’)

curr\u mon\u id在JS中,您可以将
选择按钮设置为相应的
id
。随后的单击会将其设置为相同的
id
。由于该值不会更改,观察者不会再次触发。如果您单击中间的另一个按钮,该值会更改两次,然后再次工作

描述了这种行为

您可以明确地告诉JS将单击视为事件,而不是通过添加
{priority:“event”}
来设置值,如链接中所述

因此,下面的代码片段就可以做到这一点:

my\u dt