【发布时间】:2018-10-25 15:19:43
【问题描述】:
我正在尝试使用 fileInput() 和 selectizeInput() 函数自动化 Web 应用程序。实际上,我想根据所选变量绘制相关图。
但是,我得到:
错误:同时提供“X”和“Y”或类似矩阵的“X”
我认为我的问题来自这段代码:
data03 <- reactive({
file1 <- input$file
req(file1)
dataSet <- read_excel(file1$datapath)
col <- names(dataSet)
updateSelectizeInput(session = session, inputId = "corr02", choices = col)
})
observe({
varZ <- names(data03())
})
output$corrplot <- renderPlot({
df <- data03()
if(input$dataSubmit03){
isolate({
corr <- cor(x = df, method = "pearson", use = "pairwise.complete.obs")
corrplot(corr = corr,
type = "lower",
method = "circle",
tl.col = "black",
tl.srt = 45)
})
}
})
这是我使用的全部代码。感谢您的帮助!
library(shiny)
library(xlsx)
library(corrplot)
library(readxl)
# File used for the example
data(iris)
write.xlsx(x = iris, file = "iris.xlsx")
ui <- fluidPage(
navbarPage(
tabPanel(title = "Presentation"),
tabPanel(title = "Importing data",
sidebarLayout(
sidebarPanel(
fileInput(inputId = "file",
label = "Import a file",
accept = c(".xlsx", ".txt", ".csv")
)
),
mainPanel(
width = 12,
verbatimTextOutput("table"))
)
),
navbarMenu(title = "Descriptive analytics",
tabPanel(title = "Correlogram",
sidebarLayout(
sidebarPanel(
selectizeInput(inputId = "corr02",
label = "Select the variables:",
choices = NULL,
multiple = TRUE),
br(),
actionButton(inputId = "dataSubmit03",
label = "RUN")
),
mainPanel(
plotOutput(outputId = "corrplot",
height = "600px")
)
)
)
)
)
)
server <- function(input, output, session) {
df <- reactive({
inFile <- input$file
db <- read_excel(inFile$datapath)
db <- data.frame(db)
})
df1 <- reactive({
inFile <- input$file
db <- read_excel(inFile$datapath, na = "NA")
db <- data.frame(db)
})
data03 <- reactive({
file1 <- input$file
req(file1)
dataSet <- read_excel(file1$datapath)
col <- names(dataSet)
updateSelectizeInput(session = session, inputId = "corr02", choices = col)
})
observe({
varZ <- names(data03())
})
output$corrplot <- renderPlot({
df <- data03()
if(input$dataSubmit03){
isolate({
corr <- cor(x = df, method = "pearson", use = "pairwise.complete.obs")
corrplot(corr = corr,
type = "lower",
method = "circle",
tl.col = "black",
tl.srt = 45)
})
}
})
}
shinyApp(ui = ui, server = server)
期望
现实
【问题讨论】:
标签: r shiny r-corrplot