【发布时间】:2016-06-05 15:08:09
【问题描述】:
我编写了一个相当简单的模块,由客户端上的 textInput 和更新该 textInput 值的服务器函数组成。为此,我在服务器函数中调用 updateTextInput()。但是,客户端上的 textInput 没有更新。
我应该怎么做才能让我的模块服务器函数更新客户端上的 textInput?
这是我的代码的简化版本:
带有模块定义的global.R
# Client side.
specifyInput <- function(id, points){
ns <- NS(id)
tagList(textInput(ns('points'), label='Total', value=points))
}
# Server side.
specify <- function(input, output, session){
ns <- session$ns
observe({
new.value = 2 * as.numeric(input$points)
#this line does not seem to work
updateTextInput(session, ns('points'), value = new.value)
})
# create dataframe with entered value
df <- reactive(data.frame(points = as.numeric(input$points)))
# return the dataframe
return(df())
}
ui.R
specifyInput("ttlEntry", 10)
服务器.R
function(input, output, session){
test <- reactive(callModule(specify, "ttlEntry"))
#somewhere in the code, call test()
}
实际上,当用户输入句点时,我想在输入的值后面附加一个 0.5,例如,如果用户输入“10”。然后将 textInput 更新为显示“10.5” 但是出于测试目的,我已将该代码更改为 new.value = 2 * ...
非常感谢任何帮助。
【问题讨论】: