Ошибка при загрузке данных для диаграммы рассеяния в shinydashboard - PullRequest
1 голос
/ 18 июня 2020

Я пытаюсь создать выходные диаграммы рассеяния на блестящей панели инструментов. У меня есть похожие наборы данных в течение нескольких лет, и я хочу построить график в соответствии с выбранными переменными и годом. Имя файла набора данных: Y96Total8.rda, Y97Total8.rda ... Имя набора данных: Total (data.table) .

К сожалению, я не могу загрузить набор данных правильным способом для построения результатов, и у меня есть ошибка "нечисловой c аргумент математической функции" на вкладке графика.

Если у кого-то есть предложения о том, как Было бы очень полезно создать этот сюжет с использованием блестящей приборной панели.

Код я прикрепил.

library(shiny)
library(shinydashboard)
library(data.table)
library(ggplot2)
library(plotly)
library(DT)

header <- dashboardPage(
  skin = "green",
  dashboardHeader(title = "TEST"),
  dashboardSidebar(sidebarMenu(
    dir = "ltr",
    align = "right",
    menuItem("Correlation", tabName = "Correlation", icon = icon("users"))
  )),
  dashboardBody(load(file = "data/Test.rda"),
                dir = "ltr",
                tabItems(
                  tabItem(tabName = "Correlation",
                          fluidRow(tabsetPanel(
                            tabPanel(
                              "Inputs",
                              box(
                                status = "danger",
                                solidHeader = TRUE,
                                width = 6,
                                title = "Food Expenditures Per",
                                sliderInput(
                                  inputId = "Food_Expenditures_Per2",
                                  label = "Food Expenditures",
                                  min = 0,
                                  max = 30000000,
                                  value = c(1000000, 10000000)
                                )
                              ),
                              box(
                                status = "danger",
                                solidHeader = TRUE,
                                title = "Total Expenditures Per",
                                width = 6,
                                sliderInput(
                                  inputId = "Total_Exp_Month_Per2",
                                  label = "Total Expenditures Per",
                                  min = 0,
                                  max = 100000000,
                                  value = c(1000000, 30000000)
                                )
                              ),
                              box(
                                status = "info",
                                solidHeader = TRUE,
                                title = "First Variable",
                                width = 6,
                                selectInput(
                                  "Var1",
                                  "First Variable",
                                  list("FoodExpenditure_Per", "Total_Exp_Month_Per"),
                                  selected =
                                    "FoodExpenditure_Per"
                                )
                              ),
                              box(
                                status = "info",
                                solidHeader = TRUE,
                                title = "Second Variable",
                                width = 6,
                                selectInput(
                                  "Var2",
                                  "Second Variable",
                                  list("FoodExpenditure_Per", "Total_Exp_Month_Per"),
                                  selected =
                                    "Total_Exp_Month_Per"
                                )
                              ),
                              box(
                                status = "info",
                                solidHeader = TRUE,
                                title = "Year",
                                width = 6,
                                selectInput(
                                  inputId = "slcT2Year3",
                                  label = "Year",
                                  choices =
                                    list(1390, 1391, 1392, 1393,
                                         1394, 1395, 1396, 1397),
                                  selected =
                                    1396
                                )
                              ),
                              box(
                                status = "info",
                                solidHeader = TRUE,
                                title = "Add line of best fit",
                                width = 6,
                                checkboxInput("fit", "Add line of best fit")
                              ),

                            ),
                            tabPanel(
                              "Plot"
                              ,
                              box(
                                status = "info",
                                solidHeader = TRUE,
                                width = 700,
                                height = 450,
                                plotOutput("scatterplot", width =
                                             600, height = 400)
                                ,
                                downloadButton("downloadPlot3", "Download")
                              )
                            )
                          )))
                ))
)


app_server <- function(input, output, session) {
  ##################### Scatter Plot #########################
  output$scatterplot <- renderPlot({
    y <- input$slcT2Year3
    fn3 <- paste0("data/Y", substr(y, 3, 4), "Total8.rda")
    load(fn3)

    Total <- subset(
      Total,
      FoodExpenditure_Per >= input$Food_Expenditures_Per2[1] &
        FoodExpenditure_Per <= input$Food_Expenditures_Per2[2] &
        Total_Exp_Month_Per >= input$Total_Exp_Month_Per2[1] &
        Total_Exp_Month_Per <= input$Total_Exp_Month_Per2[2]
    )


    p <- ggplot(Total, aes(input$Var1, input$Var2)) +
      geom_point() +
      scale_x_log10()

    if (input$fit == TRUE) {
      p <- p + geom_smooth(method = "lm")
    }
    p
  })


  session$onSessionEnded(function() {
    stopApp()
    #    q("no")
  })

}

shinyApp(header, app_server)

Изображение ошибки:

enter image description here

1 Ответ

0 голосов
/ 23 июня 2020

Ваш ggplot вызов следует изменить на

p <- ggplot(Total, aes(Total[[input$Var1]], Total[[input$Var2]]))
...