使用 renderUI 时出现 R 闪亮错误:找不到对象
R Shiny error when using renderUI: object not found
出于某种原因,Shiny 认为我的 renderUI
不存在。代码非常简单。我们有一个客户数据框:
DF_custs <- data.frame(ID=c(1,2,3,3), val=c(10, 20, 100, 200))
。
您只需 select 一个 ID 并取回一个值:
但我想实现一种将下拉列表中的值发送回用户的方法。所以我继续 renderUI
.
问题在于
output$dupes<-renderUI({selectInput('dupes', 'These are dupes:', choices=get_cust()$val, selected=get_cust()$val[1,])})
此行允许您查看,例如,ID 3
有两个 val
的值。这两个值将填充一个下拉列表。稍后我希望以此为基础,但现在这就是我想要做的。很简单。
我一直收到错误 Error in output$dupes <- renderUI({ : object 'output' not found
。
我觉得一切都很好。我有一个 renderUI
并且关联了 uiOutput
。我没有看到任何语法问题,也没有缺少参数。可能出了什么问题?
app.R
DF_custs <- data.frame(ID=c(1,2,3,3), val=c(10, 20, 100, 200))
server <- function(input, output, session) {
get_cust <- reactive({
cust <- DF_custs[which(DF_custs$ID == input$num), ]
return(cust$val)})
output$result <- renderText({
ans <- get_cust()
paste("Your value: ", ans)})
}
output$dupes<-renderUI({
selectInput('dupes', 'These are dupes:', choices=get_cust()$val, selected=get_cust()$val[1,])})
ui <- fluidPage(
numericInput(inputId="num", label="Pick an ID: ", value=1),
uiOutput("dupes"),
mainPanel(textOutput("result"))
)
shinyApp(ui = ui, server = server)
试试这个 server function
:
server <- function(input, output, session) {
get_cust <- reactive({
#cust <- DF_custs[which(DF_custs$ID == input$num), ]
#return(cust$val)
DF_custs
})
output$result <- renderText({
ans <- get_cust()[which(DF_custs$ID == input$num), "val"]
paste("Your value: ", ans)})
output$dupes<-renderUI({
selectInput('dupes', 'These are dupes:', choices=get_cust()$val, selected=get_cust()$val[1])
})
}
出于某种原因,Shiny 认为我的 renderUI
不存在。代码非常简单。我们有一个客户数据框:
DF_custs <- data.frame(ID=c(1,2,3,3), val=c(10, 20, 100, 200))
。
您只需 select 一个 ID 并取回一个值:
但我想实现一种将下拉列表中的值发送回用户的方法。所以我继续 renderUI
.
问题在于
output$dupes<-renderUI({selectInput('dupes', 'These are dupes:', choices=get_cust()$val, selected=get_cust()$val[1,])})
此行允许您查看,例如,ID 3
有两个 val
的值。这两个值将填充一个下拉列表。稍后我希望以此为基础,但现在这就是我想要做的。很简单。
我一直收到错误 Error in output$dupes <- renderUI({ : object 'output' not found
。
我觉得一切都很好。我有一个 renderUI
并且关联了 uiOutput
。我没有看到任何语法问题,也没有缺少参数。可能出了什么问题?
app.R
DF_custs <- data.frame(ID=c(1,2,3,3), val=c(10, 20, 100, 200))
server <- function(input, output, session) {
get_cust <- reactive({
cust <- DF_custs[which(DF_custs$ID == input$num), ]
return(cust$val)})
output$result <- renderText({
ans <- get_cust()
paste("Your value: ", ans)})
}
output$dupes<-renderUI({
selectInput('dupes', 'These are dupes:', choices=get_cust()$val, selected=get_cust()$val[1,])})
ui <- fluidPage(
numericInput(inputId="num", label="Pick an ID: ", value=1),
uiOutput("dupes"),
mainPanel(textOutput("result"))
)
shinyApp(ui = ui, server = server)
试试这个 server function
:
server <- function(input, output, session) {
get_cust <- reactive({
#cust <- DF_custs[which(DF_custs$ID == input$num), ]
#return(cust$val)
DF_custs
})
output$result <- renderText({
ans <- get_cust()[which(DF_custs$ID == input$num), "val"]
paste("Your value: ", ans)})
output$dupes<-renderUI({
selectInput('dupes', 'These are dupes:', choices=get_cust()$val, selected=get_cust()$val[1])
})
}