yif*_*yan 5 r shiny shinydashboard shinyapps
我正在使用shiny并shinydashboard创建一个仪表板。最少的示例代码如下:
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(title = "test"),
dashboardSidebar(
sidebarMenu(
menuItem(text = "Tab One",tabName = "tab1"),
menuItem(text = "Tab Two",tabName = "tab2"),
id = "sidebar"), # an extra comma here!
),
dashboardBody()
)
server <- function(input,output){}
shinyApp(ui,server)
Run Code Online (Sandbox Code Playgroud)
当我运行此应用程序时,出现错误消息:
Error in tag("section", list(...)) : argument is missing, with no default
Run Code Online (Sandbox Code Playgroud)
我知道出现此错误是因为在第10行的末尾有一个逗号。但是问题是:
我的应用程序中出现类似的错误,但是该应用程序包含20多个相互采购的R文件以及2000多个代码行。对我来说,遍历每个文件并尝试找出我放在多余逗号的位置是不可能的。
我的问题是:
有没有更简单的方法让R用行号和文件源打印错误消息?还是有一种更好的方法来调试这种错误(没有提供详细信息)?谢谢!
理想情况下,我希望错误消息类似于以下内容:
Error in source: <folder>/<file.R> 9:10: argument is missing, with no default
9: menuItem(text = "Tab Two",tabName = "tab2"),
10: id = "sidebar"), # an extra comma here!
^
Run Code Online (Sandbox Code Playgroud)
获取主文件而不是运行它,并在错误发生后运行
traceback()
Run Code Online (Sandbox Code Playgroud)
在控制台中。当我用你的简单例子来做到这一点时,我看到了这一点:
> traceback()
11: tag("section", list(...))
10: tags$section(id = "sidebarItemExpanded", class = "sidebar", `data-disable` = if (disable) 1 else NULL,
list(...))
9: tag("aside", list(...))
8: tags$aside(id = "sidebarCollapsed", class = "main-sidebar", `data-collapsed` = dataValueString,
custom_css, tags$section(id = "sidebarItemExpanded", class = "sidebar",
`data-disable` = if (disable) 1 else NULL, list(...)))
7: dashboardSidebar(sidebarMenu(menuItem(text = "Tab One", tabName = "tab1"),
menuItem(text = "Tab Two", tabName = "tab2"), id = "sidebar"),
)
6: tagAssert(sidebar, type = "aside", class = "main-sidebar")
5: dashboardPage(dashboardHeader(title = "test"), dashboardSidebar(sidebarMenu(menuItem(text = "Tab One",
tabName = "tab1"), menuItem(text = "Tab Two", tabName = "tab2"),
id = "sidebar"), ), dashboardBody()) at .active-rstudio-document#4
4: eval(ei, envir)
3: eval(ei, envir)
2: withVisible(eval(ei, envir))
1: source("~/.active-rstudio-document", echo = TRUE)
Run Code Online (Sandbox Code Playgroud)
请注意,标记的表达式5:具有行号信息: .active-rstudio-document#4。这是 RStudio 在采购之前保存的文件,该#4部分表示问题出在第 4 行。第 4 行是对dashboardPage. 除非您将代码分解为更小的表达式,否则您不会获得比这更精细的细节。这会感觉非常不自然,希望没有必要,但你可以将原始写为
library(shiny)
library(shinydashboard)
header <- dashboardHeader(title = "test")
sidebar <- dashboardSidebar(
sidebarMenu(
menuItem(text = "Tab One",tabName = "tab1"),
menuItem(text = "Tab Two",tabName = "tab2"),
id = "sidebar"), # an extra comma here!
)
body <- dashboardBody()
ui <- dashboardPage(
header,
sidebar,
body
)
server <- function(input,output){}
shinyApp(ui,server)
Run Code Online (Sandbox Code Playgroud)
当我这样做时,traceback()包括这一行:
5: dashboardSidebar(sidebarMenu(menuItem(text = "Tab One", tabName = "tab1"),
menuItem(text = "Tab Two", tabName = "tab2"), id = "sidebar"),
) at .active-rstudio-document#5
Run Code Online (Sandbox Code Playgroud)
它告诉我问题来自哪里。
编辑添加:查看回溯的另一种方法是运行
options(error = recover)
Run Code Online (Sandbox Code Playgroud)
在采购所有东西之前。运行将在显示类似显示器的情况下终止traceback(),但格式不同。它还允许您检查每个评估框架中的变量,这在此示例中可能没有帮助,但有时非常有帮助。
| 归档时间: |
|
| 查看次数: |
141 次 |
| 最近记录: |