Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/9.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,我有一个简单的闪亮应用程序的例子。这里我测试其他元素对特定元素变化的反应 ui.r library(shiny) shinyUI(fluidPage( titlePanel("SCORE CARD DEVELOPMENT PLATFORM"), navbarPage("ScoreDevApp", tabPanel("Settings", fluidRow(column(2,

我有一个简单的闪亮应用程序的例子。这里我测试其他元素对特定元素变化的反应

ui.r

 library(shiny)
 shinyUI(fluidPage(

  titlePanel("SCORE CARD DEVELOPMENT PLATFORM"),
    navbarPage("ScoreDevApp",
         tabPanel("Settings",
                  fluidRow(column(2,
                                   actionButton("goButton_service", "Load    saved parameters",width=200)
                                  ,radioButtons("DB_switch"
                                              , "Select Data Source"
                                              ,c("Oracle"=1,"text file"=2)
                                  )
                  )             
                  )
         ),
         tabPanel("Download & Binning input data",
                  fluidRow(column(2,
                                  textInput("text","test")))),
         id="ScoreDevApp"
    )
  )
)
server.r

library(shiny)
library(shinyjs)


shinyServer(function(input, output, session) {

observeEvent(input$goButton_service, {
  updateRadioButtons(session
                   , "DB_switch"
                   , "Select Data Source"
                   ,c("Oracle"=1,"text file"=2)
                   , selected = 2
                   , inline = FALSE
  )
  if(input$DB_switch==2){
    updateTextInput(session,text,"test",value="testing")
   }

  })  
})
按下按钮“goButton_service”会更新radiobutton“DB_switch”->所选项目为2而不是1(默认情况下)。这做得很好

但是接下来我要检查radiobutton的值:如果它是2,那么字符串“testing”应该被传递到选项卡面板“下载并装箱输入数据”上的textInput“text”。但是,它没有被执行。需要帮助。

尝试以下版本(我已删除启用/禁用代码,它没有任何功能)。您的主要错误是
文本
周围缺少引号

library(shiny)
library(shinyjs)


shinyServer(function(input, output, session) {
  observe({
    if (input$DB_switch == "2") {
      updateTextInput(session, "text", value = "testing")
    }
  }
  )
  observeEvent(input$goButton_service, {
    updateRadioButtons(session
                       , "DB_switch"
                       , "Select Data Source"
                       ,c("Oracle"=1,"text file"=2)
                       , selected = 2
                       , inline = FALSE
    )
  })
})

如果您更新
textInput
两次,如下面的示例所示,应该可以解决您的问题


服务器
我试过你的版本,但没有用。我在脚本中尝试了没有quaotes的选项“(if(input$DB_switch==“2”)”。您是否有假定的结果(按下按钮后,字符串“testing”应出现在文本输入“text”)中?嗯,我在您的脚本中发现了差异,并已将其删除。要使脚本正常工作,您需要编写“selected=”2“'但不是'selected=2'。更正后效果良好。如果要更正元素id和标签,它似乎会生成必要的输出。但我需要按照以下步骤进行输出:按'goButton_service'->更改radiobutton->根据radiobutton的更新值将字符串传递给textinput'text'。您可以r建议在按下按钮时传递字符串(看起来像)。
shinyServer(function(input, output, session) {

  observeEvent(input$goButton_service, {
    updateRadioButtons(session, "goButton_service", selected = 2)
    updateTextInput(session, "text", "test", value = "testing")
  }) 

  observe({
    if (input$DB_switch == 2) 
      updateTextInput(session, "text", "test", value = "testing")
  })

})