我想做的事情是:有actionLink a和actionLink b。他们可以触发UpdateNumericInput()来分配一些权重。我还可以手动更改UI中numericInput()的权重。我要实现的是单击actionLink a时,文本输出将为“ click on a”,而actionLink b发生的事情与“ click on b”相同。我还希望当我在UI上实际编辑权重时将textoutput显示为“手动更改权重”。有什么办法可以实现这一目标?
#triggered by actionLink a
apply_a_weights = observeEvent(input$a_weight_link, {
v_a = get_a_weights()
v_a = setNames(as.double(unname(v_a)), names(v_a))
for (nm in names(v_a)) {
updateNumericInput(session, nm, value = v_a[[nm]])
}
output$selected_weight <- renderUI({HTML("You have changed to <B>a weight</B>")}) }, priority = 1)
# triggered by actionLink b
apply_b_weights = observeEvent(input$b_weight_link, {
v_b = df_dmd$b_weights
names(v_b) = df_dmd$input_id
for (nm in names(v_b)) {
updateNumericInput(session, nm, value = v_b[[nm]])
}
output$selected_weight <- renderUI({HTML("You have changed to <B>b weight</B>")})}, priority = 1)
我还尝试将这部分内容作为默认文本输出放置在server.R中:
output$selected_weight <- renderUI({HTML("<B>manually</B> changed the weights")})
但是这些代码不起作用。当我自己更改权重时,“手动更改权重”不会显示。
非常感谢
答案 0 :(得分:0)
您没有提供可复制的代码,因此很难猜测。问题可能是重复的output$selected_weight
。
定义一个reactiveVal
来存储文本确实会显示,例如在server
的开头:
Text <- reactiveVal()
然后在您的两个observeEvent
中删除output$selected_weight
,然后执行以下操作:
#triggered by actionLink a
apply_a_weights = observeEvent(input$a_weight_link, {
v_a = get_a_weights()
v_a = setNames(as.double(unname(v_a)), names(v_a))
for (nm in names(v_a)) {
updateNumericInput(session, nm, value = v_a[[nm]])
}
Text("You have changed to <B>a weight</B>")
}, priority = 1)
# triggered by actionLink b
apply_b_weights = observeEvent(input$b_weight_link, {
v_b = df_dmd$b_weights
names(v_b) = df_dmd$input_id
for (nm in names(v_b)) {
updateNumericInput(session, nm, value = v_b[[nm]])
}
Text("You have changed to <B>b weight</B>")
}, priority = 1)
最后,在observeEvent
s之外,做
output$selected_weight <- renderUI({HTML(Text()})
同样,您没有提供最低限度的可重复代码,所以我不确定我的答案是否满足您的要求。