Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 闪亮动态表错误“;无法强制类型';关闭';到类型为'的向量;字符'&引用;_R_Shiny_Shiny Server - Fatal编程技术网

R 闪亮动态表错误“;无法强制类型';关闭';到类型为'的向量;字符'&引用;

R 闪亮动态表错误“;无法强制类型';关闭';到类型为'的向量;字符'&引用;,r,shiny,shiny-server,R,Shiny,Shiny Server,这是一个衍生于和类似,但不等于 我想创建一个大表,以便在一个闪亮的应用程序中在该表之后创建一些表 这是我的MWE(似乎标题有问题,UI中的h3): 完整服务器。R: 问题是my_表是一个被动表,您不能使用DT::dataTableOutput()输出被动表。只能对服务器中使用DT::renderDataTable()创建的对象执行此操作。所以 DT::dataTableOutput("my_table") 不起作用,但是 DT::dataTableOutput("more_than_10")

这是一个衍生于和类似,但不等于

我想创建一个大表,以便在一个闪亮的应用程序中在该表之后创建一些表

这是我的MWE(似乎标题有问题,UI中的h3):

完整服务器。R:
问题是my_表是一个被动表,您不能使用
DT::dataTableOutput()
输出被动表。只能对服务器中使用
DT::renderDataTable()
创建的对象执行此操作。所以

DT::dataTableOutput("my_table")
不起作用,但是

DT::dataTableOutput("more_than_10")
威尔。如果要显示整个表,还必须创建datatable,例如:

   output$my_table2 <- DT::renderDataTable(DT::datatable({
      my_table()
    }))
应该有用。希望这有帮助


编辑:您用MWE更新了答案

该MWE仍存在一些问题

  • 同一输出不能使用两次。因此,两条
    textOutput('year')
    语句将使您的应用程序无声崩溃
  • 记住什么时候是反应性的,什么时候不是。将
    input$year
    的值分配给它之后,不需要
    t()
  • 您不需要调用pacman包;)mpg数据集确实需要ggplot2
此代码适用于:

library(ggplot2)
library(shiny)
library(dplyr)
server<- function(input,output)
{


      display_table <- reactive({
        t <-  as.character(input$year) 
        # Read the RCA matrix
        long_table = tbl_df(mpg) %>% filter(year == t)
        return(long_table)
      })

      output$year = renderText(input$year)
      output$year2 = renderText(input$year)

      output$miles <- DT::renderDataTable(DT::datatable({
        display_table() %>% select(manufacturer,model,cty,hwy)
      }))

      output$desc <- DT::renderDataTable(DT::datatable({
        display_table() %>% select(manufacturer,model,trans,class)
      }))


}

ui<- shinyUI(fluidPage(

  verticalLayout(
    # Application title
    titlePanel("ggplot2's mpg dataset example"),

    mainPanel(

      # User parameters
      column(12,
             tags$h3("Parameters"), 
             selectInput('year', 'Year', c("Select year",1999:2015), selected = 1999)
      ),

      # Display tables
      column(12, 
             h3("Miles per gallon for cars made in the year",textOutput("year")),
             DT::dataTableOutput("miles"),
             h3("Description for carss made in the year",textOutput("year2")),
             DT::dataTableOutput("desc")
      )

    )
  )
))

shinyApp(ui,server)
库(ggplot2)
图书馆(闪亮)
图书馆(dplyr)

你好。谢谢!我将其更改为
output$more_than_10%filter(X1>10)})
,我看到了相同的错误。。我会继续挖掘你是否也更改了DT::dataTableOutput语句?事实上:)我更改了,非常感谢!!我将添加一个脚注,感谢您的贡献。当准备就绪时,祝您愉快!顺便说一句,在将来,如果您发布一个最简单的工作示例,将非常有帮助,请参阅。包括一些虚假数据,以便其他人可以运行您的代码。它使调试变得更容易,并帮助您解决问题。非常感谢!!我用
mpg
dataset将其更改为MWE,并相应地更新了我的答案。
   output$my_table2 <- DT::renderDataTable(DT::datatable({
      my_table()
    }))
DT::dataTableOutput("my_table2")
library(ggplot2)
library(shiny)
library(dplyr)
server<- function(input,output)
{


      display_table <- reactive({
        t <-  as.character(input$year) 
        # Read the RCA matrix
        long_table = tbl_df(mpg) %>% filter(year == t)
        return(long_table)
      })

      output$year = renderText(input$year)
      output$year2 = renderText(input$year)

      output$miles <- DT::renderDataTable(DT::datatable({
        display_table() %>% select(manufacturer,model,cty,hwy)
      }))

      output$desc <- DT::renderDataTable(DT::datatable({
        display_table() %>% select(manufacturer,model,trans,class)
      }))


}

ui<- shinyUI(fluidPage(

  verticalLayout(
    # Application title
    titlePanel("ggplot2's mpg dataset example"),

    mainPanel(

      # User parameters
      column(12,
             tags$h3("Parameters"), 
             selectInput('year', 'Year', c("Select year",1999:2015), selected = 1999)
      ),

      # Display tables
      column(12, 
             h3("Miles per gallon for cars made in the year",textOutput("year")),
             DT::dataTableOutput("miles"),
             h3("Description for carss made in the year",textOutput("year2")),
             DT::dataTableOutput("desc")
      )

    )
  )
))

shinyApp(ui,server)