【发布时间】:2021-07-30 20:34:44
【问题描述】:
我对 Shiny 还很陌生,但我试图创建一个允许用户进入并输入名字、姓氏或社会安全号码(或全部三个或两个等)的应用程序,并且然后它将 ping 一个 sql 查询并返回正确的结果。但是我遇到了以下错误。
Warning in min(x) : no non-missing arguments to min; returning Inf
Warning in max(x) : no non-missing arguments to max; returning -Inf
Warning in min(x) : no non-missing arguments to min; returning Inf
Warning in max(x) : no non-missing arguments to max; returning -Inf
Warning: Error in plot.window: need finite 'xlim' values
[No stack trace available]
下面是我的代码:
rm(list=ls())
library(shiny)
library(RODBC)
ui <- bootstrapPage(
textInput(inputId = "First_Name",
label = "First_Name",
value = "",
width = NULL,
placeholder = "Enter Client's First Name"),
textInput(inputId = "SSN",
label = "SSN",
value = "",
width = NULL,
placeholder = "Enter Client's SSN"),
textInput(inputId = "Last_Name",
label = "Last_Name",
value = "",
width = NULL,
placeholder = "Enter Client's Last Name"),
plotOutput(outputId = "main_plot", height = "300px")
)
server <- function(input, output) {
BDW <- odbcConnect("BDW", uid="", pwd="", believeNRows = FALSE)
table1 <- reactive({sqlQuery(BDW,paste("
SELECT name as 'Name:',ssn as 'SSN', a.address + ', ' + a.city + ', ' + a.state + ', ' + a.zip as 'Address:'
FROM [RM].[dbo].[CustomerMaster] a
LEFT JOIN [UVC].[dbo].[UVCWeb_CustomerFlat]b ON a.number = b.RMNumber
WHERE
name like '%",input$First_Name,"%'
and name like '%",input$Last_Name,"%'
and ssn like '%",input$SSN,"%'
and bdw_CurrentIndicator = 1"))})
output$main_plot <- renderPlot({
plot(table1()$Name, table1()$SSN, table1()$Address)
})
}
shinyApp(ui, server)
所涉及的数据非常简单,只有客户姓名、SSN 和地址。非常感谢您预先提供的所有帮助。谢谢!
【问题讨论】:
-
你的输出应该是什么?目前,您尝试生成一个图,其名字为 x 轴,SSN 为 y 轴,然后地址为什么?你真的想要一个情节还是想要一个渲染的文本?
-
@pbraeutigm 我不知道我在做什么。我真的只是想返回一张桌子。列标题为名称、SSN 和地址。它最终将成为一个可点击的表格,用户在其中选择一条记录并将它们带到另一个页面。
-
您可以使用例如“绘制”您的表格数据表库。您将编辑您的代码: dataTableOutput("mytable") 在您的 ui 和 output$mytable = DT::renderDataTable({ your data.table }) 在您的服务器。看这里:shiny.rstudio.com/articles/datatables.html
-
就是这样!非常感谢! @pbraeutigm 如果您将作为答案发布,我会接受!再次感谢您
标签: r shiny shiny-reactivity