我正在尝试将Shiny UI SelectInput的输入发送到服务器脚本和我的server.R将从表中读取特定列并计算最小值,最大值,平均值,中值数据。我能够执行此操作并在R Console中逐行执行时获得正确的数据。无法将其作为Shiny输出发送并在Shiny UI浏览器中作为表格打印。 Server.R脚本应该从UI获取输入并仅执行该特定输入的均值,中位数。感谢您的宝贵帮助。
# ui.R
library(shiny)
library(RODBC)
library(DBI)
dbconnect <- odbcConnect("orecloud", uid="XXXX", pwd="XXXX", believeNRows=FALSE)
df <- data.frame()
df <- sqlQuery(dbconnect,"SELECT distinct cpan FROM CYTOKINE ")
shinyUI(fluidPage(
headerPanel("ORE Cytokine Summary"),
sidebarLayout(
sidebarPanel(
helpText("Please select Patient Details.."),
selectInput("CPAN",
label = "Choose patient",
choices = df,
selected = NULL),
submitButton(text = "Submit", icon = NULL)),
mainPanel(
dataTableOutput("tableoutput")
)
)
))
# server.R
library(RODBC)
library(RODBC)
library(lattice)
shinyServer(
function(input, output) {
dbconnect <- odbcConnect("orecloud", uid="XXXX", pwd="XXXX", believeNRows=FALSE)
df2 = reactive({
# Created DB Connection to get details
input_var <- input$CPAN
my_query <- paste("select CPAN,SCTP,MARKER,RESULT from TABLE where CPAN= ", input_var)
sqlQuery(dbconnect,my_query)
cleandata <- na.omit(data)
colnames(cleandata)
Markers <- unique(cleandata[,"MARKER"])
#Markers
nMarkers <- length(Markers)
nMarkers
Patients <- unique(cleandata[,"CPAN"])
nPatients <- length(Patients)
nPatients
#Output columns defined
output <- data.frame("Marker","Patient", "Min","Q1","Median","Mean","Q3","Max",stringsAsFactors=FALSE,check.names=FALSE)
for (i in 1:nMarkers) {
Mrk <- Markers[i]
for (j in 1:nPatients){
Pnt <- Patients[j]
Mrkdata <- cleandata[which(cleandata[,'MARKER']== Mrk),]
Ptntdata <- Mrkdata[which(Mrkdata[,'CPAN']==Pnt), ]
output[{i-1}*nPatients+j,1] <- Mrk
output[{i-1}*nPatients+j,2] <- Pnt
for (k in 1:6){
output[{i-1}*nPatients+j,k+2] <- summary(Ptntdata[,'RESULT'])[k]
#histogram(~Mrkdata [,'RESULT'])
}
#output[j,9]<- quantile(Mrkdata[,'RESULT'],c(.25,.75))[1]
#output[j,10]<- quantile(Mrkdata[,'RESULT'],c(.25,.75))[2]
}
}
})
output$tableoutput <- renderDataTable({df2()})
} )