0

我在 app.R 中有以下代码

library(shiny)
library(highcharter)

art.data <- read.csv("./../data1.csv", stringsAsFactors = FALSE)

# Define UI for application that draws a histogram
ui <- fluidPage(

titlePanel("Art and R"),

  sidebarLayout(
    sidebarPanel(

      selectInput(
        "colspa", "Color space", choices = list("RGB" = "rgb", "HSV" = 
        "hsv", "LAB" = "lab", "LCH" = "lch", "LUV" = "luv"), selected = 1
      ),

      conditionalPanel(
        condition = "input.colspa == 'rgb'", selectInput(
           "rgbchoice", "Color choice", choices = list("Red" = "r", "Green" 
            = "g", "Blue" = "b"), selected = 1
        )
      )
    ),

    mainPanel(
      highchartOutput("distPlot", height = "500px")
    )
  )
)

# Define server logic required to draw a histogram
server <- function(input, output) {

output$distPlot <- renderHighchart({
     str1 <- paste0(input$colspa, ".", input$rgbchoice, ".avg")
     hc <- highchart() %>% hc_add_series(data = art.data, type = "scatter", 
       mapping = hcaes(x = year, y = art.data[[str1]]))

     hc

  })
}

# Run the application 
shinyApp(ui = ui, server = server)

当我运行应用程序时,我收到一条错误消息“评估错误:找不到对象'str1'。” 我已经尝试了各种方法来让它工作,但似乎没有任何工作。如何获得一个高图,其中数据框的列名是存储在 str1 中的值。

这是 art.data 一部分的快照

这是我运行应用程序时收到的错误消息的快照

(我知道这对于除 RGB 之外的任何其他选择都不起作用,但我试图让 RGB 仅首先工作。)

4

0 回答 0