我目前正在开发一个闪亮的应用程序,我无法用使用textInput sqldf()从dataframe检索的值更新。数据文件看起来像这样
Email First Last
1 abc.yyz@gmail.com abc yyz
2 vvv.rrr@gmail.com vvv rrr问题是当我选择电子邮件时,它应该在textInput1中显示名字,在TextInput2中显示姓氏。
所用的代码是:
if (interactive()) {
ui <- fluidPage(
selectizeInput('email', 'Enter Email ID', choices = sam,options = list(
placeholder = "Please select your Email ID",
onInitialize = I('function() { this.setValue(""); }'))),
textInput('fn', ' Enter your First Name'),
textInput('ln', 'Enter your Last Name')
)
server <- function(input, output, session) {
observeEvent(input$email,{
check <- paste(input$email)
fetchvalue <- sqldf("select * from dataset where `Email` == 'check'")
first <- fetchvalue$First
updateTextInput(session, "fn",value = first)
})
}
shinyApp(ui, server)
}有人能帮助解决这个问题吗?提前感谢
发布于 2018-10-06 13:28:43
你的应用程序代码看起来很好。这是你的应用程序的mwe -
library(shiny)
library(dplyr)
shinyApp(
ui = fluidPage(
selectizeInput('email', 'Enter Email ID', choices = paste0(letters, "@example.com"), options = list(
placeholder = "Please select your Email ID",
onInitialize = I('function() { this.setValue(""); }'))),
textInput('fn', ' Enter your First Name'),
textInput('ln', 'Enter your Last Name')
),
server = function(input, output, session) {
observeEvent(input$email,{
# check <- paste(input$email)
fetchvalue <- data_frame(Email = paste0(letters, "@example.com"), First = LETTERS) %>% filter(Email == input$email)
first <- fetchvalue$First
updateTextInput(session, "fn", value = first)
})
}
)正如我在评论中提到的,我怀疑您的sqldf查询是错误的。试一试这个
fetchvalue <- sqldf(sprintf("select * from dataset where Email = '%s'", input$email))
https://stackoverflow.com/questions/52676032
复制相似问题