我hava和行动botton id = do,我想要更改的价值和输入称为rhm_clic当单击acion boton。我现在有这个。更改从服务器闪亮的输入值
observeEvent(input$do,{
input$rhm_clic<-NULL
})
我hava和行动botton id = do,我想要更改的价值和输入称为rhm_clic当单击acion boton。我现在有这个。更改从服务器闪亮的输入值
observeEvent(input$do,{
input$rhm_clic<-NULL
})
您不能通过这种方式更改闪亮创建的输入值。对于要更改的变量input$
,需要通过实际输入过程(如inputText()
或actionButton()
)更改该变量。从技术上来说,这是一种额外的方式,但这是一个无证的工作,对这个问题毫无意义。如果您需要使用类似于闪亮的input$
的无功变量,则必须使用reactiveValues()
函数调用创建一个。如果您只是将一个值分配给一个变量,则不需要一个无功变量。如果您试图将先前创建的值重置为NULL,则必须创建一个反应变量并将其设置为NULL。以下是如何使用按钮将无反应变量设置为值或NULL。
actionButton("do","Putlabelhere")
observeEvent(input$do,{
rhm_clic <- value #or NULL
return(rhm_clic)
#the return is not needed but a good idea for beginners
}
我不知道我无法改变输入的方式。我也用过你的方法,但他们没有工作。最后,我选择从JavaScript创建一个按钮操作并使用Shiny.onInputChange JavaScript函数。以下代码在ui中解决了我的问题 'HTML(' '), 标签$脚本(' 的document.getElementById( “mydiv”)的onclick =函数(){ VAR数=的Math.random(); Shiny.onInputChange( “MYDATA”,数); } ; ')' –
代码解决了问题是\\ '''HTML('<按钮的ID = “mydiv” 类型= “按钮” 类=“BTN BTN-默认操作按钮光泽-bound-输入“> 更改值 '), 标签$脚本(' 的document.getElementById( “mydiv”)的onclick =函数(){VAR 数=的Math.random()。 Shiny.onInputChange(“mydata”,number); }; “)''' –
最后,我选择了从JavaScript创建按钮操作并使用Shiny.onInputChange JavaScript函数。下面的代码,在用户界面,解决我的问题
#Create a button with HTML, with a specific id
HTML('<button id="mydiv" type="button"
class="btn btn-default action-button shiny-bound-input">
Change The Value</button>'),
#Using the javaScript Shiny.onInputChange function to restore the input value.
tags$script(' document.getElementById("mydiv").onclick = function() {
Shiny.onInputChange("mydata", number); }; ')
根据输入的类型,你可以用'闪亮:: updateXXXInput'或'闪亮:: updateYYYButton' - 你必须有一个会话参数在'server'函数中。看看'?updateNumericInput' – HubertL
我使用了更新功能,但他们没有工作。难道是因为我用JavaScript创建了Shiny.onInputChange输入? –