Shiny应用在项目根目录中运行时出现错误。

huangapple go评论81阅读模式
英文:

Shiny app error when running in app in the project root folder

问题

当我尝试在项目根目录中运行忠诚演示Shiny应用程序时,出现错误Error in data$grid : object of type 'closure' is not subsettable,这是在子目录中使用的代码,与Shiny忠诚应用程序完全无关。然而,如果我从子目录中运行忠诚应用程序,它可以正常运行。在同一个项目中还有其他几个文件夹和脚本。我已经关闭并重新打开了RStudio并删除了历史文件,但仍然出现相同的错误。是否存在某种损坏?

#
# 这是一个Shiny Web应用程序。您可以通过点击上面的“运行应用程序”按钮来运行应用程序。
#
# 了解更多关于使用Shiny构建应用程序的信息:
#
#    http://shiny.rstudio.com/
#

library(shiny)

# 定义绘制直方图的应用程序的UI
ui <- fluidPage(

    # 应用程序标题
    titlePanel("Old Faithful Geyser Data"),

    # 侧边栏,用于设置柱数的滑块输入
    sidebarLayout(
        sidebarPanel(
            sliderInput("bins",
                        "柱数:",
                        min = 1,
                        max = 50,
                        value = 30)
        ),

        # 显示生成的分布图的主面板
        mainPanel(
           plotOutput("distPlot")
        )
    )
)

# 定义绘制直方图所需的服务器逻辑
server <- function(input, output) {

    output$distPlot <- renderPlot({
        # 根据来自ui.R的input$bins生成柱
        x    <- faithful[, 2]
        bins <- seq(min(x), max(x), length.out = input$bins + 1)

        # 使用指定数量的柱绘制直方图
        hist(x, breaks = bins, col = 'darkgray', border = 'white',
             xlab = '等待下次喷发时间(分钟)',
             main = '等待时间的直方图')
    })
}

# 运行应用程序
shinyApp(ui = ui, server = server)
英文:

When I try to run the faithful demo shiny app in the project root folder I get the error Error in data$grid : object of type &#39;closure&#39; is not subsettable
which is code used in different script in a sub folder, completely unrelated to the shiny faithful app. However if I run the faithful app from a sub folder it runs correctly. There are several other folders and scripts in the same project. I've closed and re-opened RStudio and deleted the history file but get the same error. Is something corrupt?

#
# This is a Shiny web application. You can run the application by clicking
# the &#39;Run App&#39; button above.
#
# Find out more about building applications with Shiny here:
#
#    http://shiny.rstudio.com/
#

library(shiny)

# Define UI for application that draws a histogram
ui &lt;- fluidPage(

    # Application title
    titlePanel(&quot;Old Faithful Geyser Data&quot;),

    # Sidebar with a slider input for number of bins 
    sidebarLayout(
        sidebarPanel(
            sliderInput(&quot;bins&quot;,
                        &quot;Number of bins:&quot;,
                        min = 1,
                        max = 50,
                        value = 30)
        ),

        # Show a plot of the generated distribution
        mainPanel(
           plotOutput(&quot;distPlot&quot;)
        )
    )
)

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

    output$distPlot &lt;- renderPlot({
        # generate bins based on input$bins from ui.R
        x    &lt;- faithful[, 2]
        bins &lt;- seq(min(x), max(x), length.out = input$bins + 1)

        # draw the histogram with the specified number of bins
        hist(x, breaks = bins, col = &#39;darkgray&#39;, border = &#39;white&#39;,
             xlab = &#39;Waiting time to next eruption (in mins)&#39;,
             main = &#39;Histogram of waiting times&#39;)
    })
}

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

答案1

得分: 0

当Shiny应用程序运行时,它会加载位于./R目录中的所有脚本(相对于应用程序本身),这是一种有用的方式,可以添加额外的函数等来支持您的应用程序(而不会使应用程序文件变得庞大)。如果您不希望加载这些脚本,您可以将应用程序或脚本移动到其他地方,或者首先将auto-load选项设置为false,如之前的问题中所述。

options(shiny.autoload.r = FALSE)
runApp()
英文:

When the shiny app runs, it loads all scripts in the ./R directory (relative to the app itself), which is a useful way to add additional functions etc. to support your app (without making your app files enormous). If you don't want those scripts loaded you will either need to move the app somewhere else or the scripts somewhere else, or first set the auto-load option to false as mentioned in a previous question

options(shiny.autoload.r = FALSE)
runApp()

huangapple
  • 本文由 发表于 2023年1月9日 10:25:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/75052673.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定