简体   繁体   English

错误:R Shiny图的第一个参数无效

[英]Error: invalid first argument with R Shiny plot

I have written an R script to train myself and others on Shiny, with R. 我写了一个R脚本,用R对自己和其他人进行Shiny培训。

One can select a dataset and plot an 'x' and 'y' variable on a base plot. 可以选择一个数据集,并在基本图上绘制“ x”和“ y”变量。 There are a couple of other user defined arguments also. 也有几个其他用户定义的参数。 It all works, however it also kicks 'Error: invalid first argument', which can be seen on the 'Plot' tab (on the shiny dashboard). 一切正常,但是还会出现“错误:无效的第一个参数”,可以在“绘图”选项卡上(在闪亮的仪表板上)看到。

I have included a 'Submit' button to pause the process down and you can see the error sign clearly, with out the submit button the the error flashes briefly, disappears and then everything works. 我提供了一个“提交”按钮来暂停该过程,您可以清楚地看到错误标志,而没有“提交”按钮的情况下,错误会短暂闪烁,然后消失,然后一切正常。

Additional information in the console suggests it may have something to do with a 'get' command, but I can't see what it may refer to further, and what to do about it. 控制台中的其他信息表明它可能与“ get”命令有关,但我看不到它可能进一步涉及什么以及如何处理。

Any ideas welcome, thanks. 任何想法都欢迎,谢谢。

The 2 shiny files = 2个闪亮的文件=

ui.R ui.R

library(shiny)
data_sets = c("iris", "mtcars", "trees")

shinyUI(fluidPage(

  titlePanel(h1("Plotting Playaround")),

    sidebarLayout(

    sidebarPanel(

      selectInput("var_data", "Select a dataset to plot up!", choices = data_sets),
      br(),
      uiOutput("x_var"),
      br(),
      uiOutput("y_var"),
      br(),
      br(),
      selectInput("plt_pts", "What sorta plot points do ya want?", 
              choices = c("points" = "p" ,
                          "lines" = "l" ,
                          "both" = "b" ,
                          "lines_only" = "c" ,
                          "overplotted" = 'o' ,
                          "hist_like" = 'h' ,
                          "stairs" = "s" ,
                          "alt_stairs"= "S",
                          "no_plot" = "n" )),
      radioButtons("plt_col", "Choose a colour!", 
               choices = c("Red",
                           "Green",
                           "Blue")),
      submitButton("Submit!")

    ),

    mainPanel(

      tabsetPanel(type = 'tab',
        tabPanel("Plot", plotOutput("p")),
        tabPanel("Summary", verbatimTextOutput("sum"))

      ) # tabsetPanel
      ) # mainPanel
)))

server.R server.R

library(shiny)
shinyServer(function(input, output){

  # reactive variables
  data_var = reactive({
    switch (input$var_data,
      "iris" = names(iris),
      "mtcars" = names(mtcars),
      "trees" = names(trees)
    )
  })

 my_data = reactive({
    switch (input$var_data,
        "iris" = iris,
        "mtcars" = mtcars,
        "trees" = trees
   )
  })

    pltpts = reactive({
    as.character(input$plt_pts)
  })

  pltcol = reactive({
    input$plt_col
  })

  # outputs
  output$x_var = renderUI({
    selectInput("variablex", "Select the 'X' variable!", choices = data_var())
  })

  output$y_var = renderUI({
selectInput("variabley", "select the 'Y' variable", choices = data_var())

}) })

  output$p = renderPlot({
    attach(get(input$var_data))
    plot(x = get(input$variablex), 
         y = get(input$variabley), 
         xlab = input$variablex, 
         ylab = input$variabley, 
         type = pltpts(),
         col = pltcol())
  })

  output$sum = renderPrint({
    summary(my_data())
  })
})

Since you're creating selectInput dynamically you need to check for NULL in your renderPlot . 由于您是动态创建selectInput ,因此需要在renderPlot检查NULL Like so: 像这样:

output$p = renderPlot({   
    if(is.null(input$variablex) || is.null(input$variabley)){return()}

    attach(get(input$var_data))
    plot(x = get(input$variablex), 
         y = get(input$variabley), 
         xlab = input$variablex, 
         ylab = input$variabley, 
         type = pltpts(),
         col = pltcol())
  })

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在闪亮的应用程序中返回绘图时返回无效的第一个参数错误 - Returning an invalid first argument error when returning a plot in a shiny app R Shiny 因用户输入无效而崩溃(长度为 0 的错误参数) - R Shiny Crashing for invalid user input (Error argument of length 0) R闪亮:文件错误(文件,“ rt”):无效的“描述”参数 - R shiny: Error in file(file, “rt”) : invalid 'description' argument R 64位闪亮错误:无效的“ nchars”参数 - R 64-bit shiny ERROR: invalid 'nchars' argument 条形图错误与Shiny R - Bar plot error with Shiny R R Shiny中类型为“ closure”的无效“ envir”参数 - invalid 'envir' argument of type 'closure' in R shiny 在 Shiny 反应式表达式中访问环境 hash 时出错。 错误消息:获取错误:第一个参数无效 - Error accessing environment hash in Shiny reactive expression. Error Message: Error in get: invalid first argument 闪亮的输入中出现“无效参数”的消息错误 - Message error with “invalid argument” in shiny inputs Leaftlet/shiny R map returning "ERROR: invalid 'type' (list) of argument" when combination chosen doesn't exist - Leaftlet/shiny R map returning "ERROR: invalid 'type' (list) of argument" when combination chosen doesn't exist R Shiny:错误导航栏页参数缺失,没有默认值,shiny ZE1E1D30D405731283E9 - R Shiny: Error Navbarpage Argument is missing with no default, shiny R
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM