【问题标题】:r - Error in tag$head: object of type 'closure' is not subsettabler - tag$head 中的错误:“闭包”类型的对象不是子集
【发布时间】:2016-03-30 17:37:44
【问题描述】:

我在笔记本电脑上运行 Shiny 应用程序时遇到此错误。 应用程序在我使用库(git2r)添加一行代码之前工作。 在我的代码下面。

有人可以帮忙吗?谢谢。

ui.R

league_desc <- c("Premier League","Serie A","Bundesliga","La Liga")

shinyUI(
  fluidPage(
    headerPanel(h1('Football Statistics', align = "center"),
                h2('Data on the 4 main european football leagues. Period 2011 - 2015', align = "center")),
             sidebarPanel(
               h4('Selection Parameters', align = "center"),

这是我的 ui.R 文件的初始部分。 请注意我使用的是 fluidPage 命令,即使我没有应用特定的格式选项(我没有“www”文件夹或“bootstrap.css”文件)。

Shiny Web 应用的用户界面定义。

library(devtools)
library(git2r)
library(shiny)
library(rCharts)
library(dplyr)
library(rjson)
library(rNVD3)

league_desc <- c("Premier League","Serie A","Bundesliga","La Liga")

shinyUI(
  fluidPage(
    headerPanel(h1('Football Statistics', align = "center"),
                h2('Data on the 4 main european football leagues. Period 2011 - 2015', align = "center")),
             sidebarPanel(
               h4('Selection Parameters', align = "center"),
               radioButtons("League_RB", 
                            "Select League", 
                            league_desc, 
                            selected = "Premier League", 
                            inline = FALSE, 
                            width = NULL),
               radioButtons("Year_RB", 
                                  "Select Season", 
                                  c(2011:2015), 
                                  selected = 2011, 
                                  inline = FALSE, 
                                  width = NULL),
               sliderInput("matchdays", 
                            "Matchdays:", 
                            min = 1,
                            max = 38,
                            value = c(1, 38))
             ),
             mainPanel(
               tabsetPanel(
                       tabPanel(p(icon("line-chart"), "Charts"),
                               h4('Standings', align = "center"),
                               showOutput("chart1"),
                               h4('Shots & Goals', align = "center"),
                               showOutput("chart2"),
                               h4('Relationship Shots vs Goals', align = "center"),
                               showOutput("chart3"),
                               h4('Fouls', align = "center"),
                               showOutput("chart4")),
                       tabPanel(p(icon("table"), "Full Data"),
                                dataTableOutput("dataTable")),
                       tabPanel(p(icon("cogs"), "Regression"),
                                h4('Predict Number of Goals based on Number of Shots on Target', align = "left"),
                                numericInput("sot","1) Expected Number of Shots on Target",value=0,min=0),
                                radioButtons("League_Pred_RB", 
                                             "2) Select League for which you want to predict", 
                                             league_desc, 
                                             selected = "Premier League", 
                                             inline = FALSE, 
                                             width = NULL),
                                h5("3) Click the button to generate the prediction"),
                                actionButton("predButton", "Generate Prediction"),
                                h5('4) Number of Goals Predicted, based on Historical Data'),
                                verbatimTextOutput("pred_goals"),
                                br(),
                                h4('Average Number of Goals, SOT and Regression Coefficients in the period 2011 - 2015', align = "left"),
                                dataTableOutput("regressionTable")
                       )
               )
    )
)
)

【问题讨论】:

  • 还有headerPanel windowTitle 必须是性格(我的想法)
  • 我用剩下的部分代码更新了之前的帖子。请让我知道您是否还需要 server.R 代码
  • 问题真的在git2r,当你加载它时你可以看到The following object is masked from ‘package:shiny’: tag。如果您加载 git2r 而不是 shiny 一切正常(需要在它之前重新启动会话)

标签: r closures shiny subset


【解决方案1】:

两个包功能相同的问题。

shiny i unloadNamespace("shiny") 中取消屏蔽函数tag 并在所有包require(shiny) 之后再次加载

效果很好。如果您需要不闪亮的标签,请使用::

library(devtools) 
        library(git2r)
    unloadNamespace("shiny")
        library(shiny)
        library(rCharts)
        library(dplyr)
        library(rjson) 
library(rNVD3)




        league_desc <- c("Premier League","Serie A","Bundesliga","La Liga")

        shinyUI( fluidPage(
          headerPanel(h1('Football Statistics', align = "center")
                      , h2('Data on the 4 main european football leagues. Period 2011 - 2015', align = "center")),
          sidebarPanel( h4('Selection Parameters', align = "center"),
                        radioButtons("League_RB", "Select League", league_desc, selected = "Premier League", inline = FALSE, width = NULL),
                        radioButtons("Year_RB", "Select Season", c(2011:2015), selected = 2011, inline = FALSE, width = NULL), 
                        sliderInput("matchdays", "Matchdays:", min = 1, max = 38, value = c(1, 38)) ),
          mainPanel( tabsetPanel(
            tabPanel(p(icon("line-chart"), "Charts"),
                     h4('Standings', align = "center") ,

                     showOutput(outputId = "chart1"),
                     h4('Shots & Goals', align = "center"),

                     showOutput("chart2"), h4('Relationship Shots vs Goals', align = "center"), 
                     showOutput("chart3"), h4('Fouls', align = "center"),
                     showOutput("chart4")
                    ), 
            tabPanel(p(icon("table"), "Full Data"), dataTableOutput("dataTable")),
            tabPanel(p(icon("cogs"), "Regression"), h4('Predict Number of Goals based on Number of Shots on Target', align = "left"), 
                     numericInput("sot","1) Expected Number of Shots on Target",value=0,min=0), 
                     radioButtons("League_Pred_RB", "2) Select League for which you want to predict", league_desc, selected = "Premier League", inline = FALSE, width = NULL), 
                     h5("3) Click the button to generate the prediction"), 
                     actionButton("predButton", "Generate Prediction"),
                     h5('4) Number of Goals Predicted, based on Historical Data'),
                     verbatimTextOutput("pred_goals"),
                     br(),
                     h4('Average Number of Goals, SOT and Regression Coefficients in the period 2011 - 2015', align = "left"),
                     dataTableOutput("regressionTable") ) ) ) ) )

【讨论】:

  • 嗨 Batanichek,您的建议奏效了!现在显示应用程序,即使我检索到不同的错误消息(“.getReactiveEnvironment()$currentContext() 中的错误:没有活动的反应上下文不允许操作。(你试图做一些只能从内部完成的事情)反应式表达或观察者。)”)。您还有其他建议要提供吗?它还告诉我对象“tag”被“package:git2r”屏蔽了:您能否就取消屏蔽“tag”的工作方式提供一些额外的解释?非常感谢!
  • 1)"Error in .getReactiveEnvironment()$currentContext() 这是你的服务器错误。R(我认为)在 UI 中你没有反应内容 2)当两个包具有相同名称的函数或对象时 - R 掩码第一个(来自第一个调用的包)当您使用第二个包调用 library 时。当你重新加载包时,你会从第二个屏蔽函数
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-07
  • 1970-01-01
  • 2023-03-27
  • 1970-01-01
  • 2018-06-22
  • 2018-02-08
相关资源
最近更新 更多