错误 CoordTern 需要以下缺失的美学(tlr->xy):z 在 Shiny 中使用 ggtern 时
Error CoordTern requires the following missing aesthetics (tlr->xy) : z when using ggtern in Shiny
我正在尝试编写一个 Shiny 应用程序,它读取一个包含以下内容的文件
三个组分系统并使用 ggtern 包绘制三元相图。
我可以在基本的 R 中做到这一点,但是当我试图将它作为 Shiny 的一部分实现时,我得到了错误,我不确定如何修复:
错误:CoordTern 需要以下缺失的美学 (tlr->xy):z
该应用程序由 fileInput 小部件和三个 selectrenderUI 函数的输入小部件组成,以便用户可以 select 来自文件的三元图的每个角的变量。
我使用的是最新的库版本:
ggplot2 3.3.0 和 ggtern 3.3.0
这是作为数据框的“.csv”文件的内容:
df <- data.frame("Comp1" = c(0.3, 0.5, 0.6, 0.75, 0.8),
"Comp2" = c(0.3, 0.25, 0.15, 0.15, 0.1),
"Comp3" = c(0.4, 0.25, 0.25, 0.1, 0.1),
"Value" = c(300, 500, 1200, 2500, 4500))
由 reprex package (v0.2.1)
于 2020-04-13 创建
下面是闪亮代码的代表:
#
# Ternary Phase Plot
#
library(shiny)
library(ggplot2)
library(ggtern)
#> --
#> Remember to cite, run citation(package = 'ggtern') for further info.
#> --
#>
#> Attaching package: 'ggtern'
#> The following objects are masked from 'package:ggplot2':
#>
#> aes, annotate, ggplot, ggplot_build, ggplot_gtable,
#> ggplotGrob, ggsave, layer_data, theme_bw, theme_classic,
#> theme_dark, theme_gray, theme_light, theme_linedraw,
#> theme_minimal, theme_void
library(DT)
#>
#> Attaching package: 'DT'
#> The following objects are masked from 'package:shiny':
#>
#> dataTableOutput, renderDataTable
ui <- fluidPage(
titlePanel("Ternary Phase Plot"),
sidebarLayout(
sidebarPanel(
fileInput("file","Upload '.csv' file"),
br(),
uiOutput("vx"), # vx is coming from renderUI in server
br(),
uiOutput("vy"), # vy is coming from renderUI in server
br(),
uiOutput("vz") # vy is coming from renderUI in server
),
mainPanel(
plotOutput("plot", height = "800px"),
DT::dataTableOutput("table")
)
)
)
server <- function(input, output, session) {
# get the names of the variables from the data file and used them in the selectInput part of the renderUI function
vars <- reactive({
req(input$file)
names(read.csv(input$file$datapath,
header = TRUE,
sep = ","))
})
# read the data file
df <- reactive({
req(input$file)
read.csv(input$file$datapath,
header = TRUE,
sep = ",")
})
output$vx <- renderUI({
selectInput("varx", "Select the 1st (L) component", choices = vars())
})
output$vy <- renderUI({
selectInput("vary", "Select the 2nd (T) component", choices = vars())
})
output$vz <- renderUI({
selectInput("varz", "Select the 3rd (R) component", choices = vars())
})
# render plot
output$plot <- renderPlot({
ggtern(df(), aes_string(x=input$varx, y=input$vary, z=input$varz)) +
geom_point(aes(fill=Value), color="black",shape=21, size=6) +
labs(fill="Value")
})
# print dataframe in table to confirm it is read properly
output$table <- DT::renderDataTable(
df()
)
}
# Run the application
shinyApp(ui = ui, server = server)
我从另一个堆栈溢出问题 () 中找到了问题的答案。它的工作虽然
提供答案以解决不同的问题。
ggtern 函数需要放在 print() 命令中。
我正在尝试编写一个 Shiny 应用程序,它读取一个包含以下内容的文件 三个组分系统并使用 ggtern 包绘制三元相图。
我可以在基本的 R 中做到这一点,但是当我试图将它作为 Shiny 的一部分实现时,我得到了错误,我不确定如何修复:
错误:CoordTern 需要以下缺失的美学 (tlr->xy):z
该应用程序由 fileInput 小部件和三个 selectrenderUI 函数的输入小部件组成,以便用户可以 select 来自文件的三元图的每个角的变量。
我使用的是最新的库版本: ggplot2 3.3.0 和 ggtern 3.3.0
这是作为数据框的“.csv”文件的内容:
df <- data.frame("Comp1" = c(0.3, 0.5, 0.6, 0.75, 0.8),
"Comp2" = c(0.3, 0.25, 0.15, 0.15, 0.1),
"Comp3" = c(0.4, 0.25, 0.25, 0.1, 0.1),
"Value" = c(300, 500, 1200, 2500, 4500))
由 reprex package (v0.2.1)
于 2020-04-13 创建下面是闪亮代码的代表:
#
# Ternary Phase Plot
#
library(shiny)
library(ggplot2)
library(ggtern)
#> --
#> Remember to cite, run citation(package = 'ggtern') for further info.
#> --
#>
#> Attaching package: 'ggtern'
#> The following objects are masked from 'package:ggplot2':
#>
#> aes, annotate, ggplot, ggplot_build, ggplot_gtable,
#> ggplotGrob, ggsave, layer_data, theme_bw, theme_classic,
#> theme_dark, theme_gray, theme_light, theme_linedraw,
#> theme_minimal, theme_void
library(DT)
#>
#> Attaching package: 'DT'
#> The following objects are masked from 'package:shiny':
#>
#> dataTableOutput, renderDataTable
ui <- fluidPage(
titlePanel("Ternary Phase Plot"),
sidebarLayout(
sidebarPanel(
fileInput("file","Upload '.csv' file"),
br(),
uiOutput("vx"), # vx is coming from renderUI in server
br(),
uiOutput("vy"), # vy is coming from renderUI in server
br(),
uiOutput("vz") # vy is coming from renderUI in server
),
mainPanel(
plotOutput("plot", height = "800px"),
DT::dataTableOutput("table")
)
)
)
server <- function(input, output, session) {
# get the names of the variables from the data file and used them in the selectInput part of the renderUI function
vars <- reactive({
req(input$file)
names(read.csv(input$file$datapath,
header = TRUE,
sep = ","))
})
# read the data file
df <- reactive({
req(input$file)
read.csv(input$file$datapath,
header = TRUE,
sep = ",")
})
output$vx <- renderUI({
selectInput("varx", "Select the 1st (L) component", choices = vars())
})
output$vy <- renderUI({
selectInput("vary", "Select the 2nd (T) component", choices = vars())
})
output$vz <- renderUI({
selectInput("varz", "Select the 3rd (R) component", choices = vars())
})
# render plot
output$plot <- renderPlot({
ggtern(df(), aes_string(x=input$varx, y=input$vary, z=input$varz)) +
geom_point(aes(fill=Value), color="black",shape=21, size=6) +
labs(fill="Value")
})
# print dataframe in table to confirm it is read properly
output$table <- DT::renderDataTable(
df()
)
}
# Run the application
shinyApp(ui = ui, server = server)
我从另一个堆栈溢出问题 (