我想使用 Shiny 创建一个三元绘图仪表板。但我陷入了这个错误。此代码采用 CSV 文件并更新三个下拉输入。然后创建的三元图具有这三个下拉值。问题是我不断从“aes”函数中收到一个错误,告诉我找不到对象“x_s”。这是我的代码:
ui <- fluidPage(
plotOutput("ggtern"),
fileInput("csv_file", "source", multiple = FALSE, accept = "csv",
width = NULL, buttonLabel = "Browse...",
placeholder = "No file selected"),
selectInput("x_val", "Choose x values:", choices=c()),
selectInput("y_val", "Choose y values:", choices=c()),
selectInput("z_val", "Choose z values:", choices=c()),
)
server <- function(input, output) {
selectedData <- reactive({
inFile <- input$csv_file
if (is.null(inFile))
return(NULL)
df <- read.csv(inFile$datapath,na.strings = c("", "NA", "#N/A"))
updateSelectInput(session,"x_val","x series",colnames(df))
updateSelectInput(session,"y_val","y series",colnames(df))
updateSelectInput(session,"z_val","z series",colnames(df))
return(df)
})
T1 <- reactive({
if (is.null(selectedData()))
return(NULL)
temp <- selectedData()[input$x_val]
return (unlist(temp))
})
T2 <- reactive({
if (is.null(selectedData()))
return(NULL)
temp <- selectedData()[input$y_val]
return (unlist(temp))
})
T3 <- reactive({
if (is.null(selectedData()))
return(NULL)
temp <- selectedData()[input$z_val]
return (unlist(temp))
})
output$ggtern <- renderPlot({
if (is.null(selectedData()))
return(NULL)
x_s <- T1()
y_s <- T2()
z_s <- T3()
vec <- aes(x_s,y_s,z_s)
obj <- ggtern(data=selectedData(), vec)
print(obj)
})
}
shinyApp(ui = ui, server = server)
我尝试了许多其他方法来实现这一点,但每次我得到同样的错误。