【问题标题】:Shiny app that works locally cannot be deployed in shinyapps.io because of not being able to locate the dataframe由于无法定位数据框,无法在 Shinyapps.io 中部署本地运行的闪亮应用
【发布时间】:2021-01-27 00:35:20
【问题描述】:

我创建了一个运行良好的闪亮应用程序,但是当我尝试将其部署到 shinyapps.io 时,出现以下错误。 Error in value[[3L]](cond) : object 'all2' not found。为什么找不到all2?我的原始文件是一个excel文件,我存储在我的工作目录中并上传到rstudio中

library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
library(visNetwork)
library(shinyWidgets)
library(igraph)

shinyApp(
  ui = dashboardPagePlus(
    header = dashboardHeaderPlus(title = "Network Viz."
      
    ),
    sidebar = dashboardSidebar(
      pickerInput(
        inputId = "ctype"
        ,
        label = "Select Country" 
        ,
        choices = unique(all2$Country)
        ,
        selected = unique(all2$Country)[1],
        multiple = T,options = list(`actions-box` = TRUE)
        
      ),
      uiOutput("lang"),
      uiOutput("top")
      
    ),
    body = dashboardBody(#This hides the temporary warning messages while the plots are being created
      tags$style(type="text/css",
                 ".shiny-output-error { visibility: hidden; }",
                 ".shiny-output-error:before { visibility: hidden; }"
      ),
      visNetworkOutput("network")
    )
    
  ),
  server = function(input, output) { 
    ID<-c(1,2,3,4)
    Name<-c("j","dd","ff","fcf")
    Language<-c("en","fr","gr","gh")
    Country<-c("EN","FR","GR","GRE")
    Topic<-c("sc","sc","ghgf","vb")
    Follow<-c(34,56,76,76)
    Social<-c("Facebook","Facebook","Twitter","Twitter")
    all2<-data.frame(ID,Name,Language,Country,Topic,Follow,Social)
    dtnew<-reactive({
      new<-subset(all2, Country %in% input$ctype)
      
    })
    
    output$lang<-renderUI({
      pickerInput(
        inputId = "l1",
        label = "Select Language",
        choices = unique(dtnew()$Language),
        multiple = TRUE,
        selected = unique(dtnew()$Language)[1],
        
        options = list(`actions-box` = TRUE)
      )
    })
    output$top<-renderUI({
      pickerInput(
        inputId = "t1",
        label = "Select Topic",
        choices = unique(dtnew()$Topic),
        multiple = TRUE,
        selected = unique(dtnew()$Topic)[1],
        
        options = list(`actions-box` = TRUE)
      )
    })
    dtnew2<-reactive({
      new2<-subset(all2, Country %in% input$ctype&Language%in% input$l1&Topic%in% input$t1)
      
    })
    output$network <- renderVisNetwork({
        nodes<-dtnew2()
        nodes<-nodes[,-c(3,4)]
        nodes<-nodes[,-4]
        colnames(nodes)<-c("id","label","group","Platform")
        nodes$value<-nodes$id
        
        id<-c(nrow(nodes)+1,nrow(nodes)+2)
        label<-unique(nodes$Platform)
        group<-c("Social","Social")
        Platform<-unique(nodes$Platform)
        value<-c(nrow(nodes)+1,nrow(nodes)+2)
        
        
        ft<-data.frame(id,label,group,Platform,value)
        
        nodes<-rbind(nodes,ft)
        
        nodes<-nodes[!duplicated(nodes[2]),]
        nodes<-nodes[,-4]
        nodes$id <- nodes$label
        nodes$value <- seq.int(nrow(nodes))
        nodes$title<-paste0("<p>","Name:",nodes$label,"<br>","Group:",nodes$group,"</p>")
        edges<-dtnew2()
        edges<-edges[,c(2,6,7)]
        colnames(edges)<-c("from","value","to")
        edges$title<-edges$value
        
        
        
        visNetwork(nodes, edges, height = "500px", width = "100%") %>% 
          visOptions(highlightNearest = list(enabled = T, hover = T),nodesIdSelection = T) %>%
          visLayout(randomSeed = 123)%>%
          visInteraction(navigationButtons = TRUE)%>%
          visIgraphLayout() 
      
      
      
    })
    }
)

【问题讨论】:

  • 您也需要在应用内上传文件。将文件加载到 R 会话并不意味着它已上传到 shinyapps.io。您还需要上传 excel 文件和读取 excel 文件的脚本到 shinyapps.io
  • 我在 server.r 中使用了 all2
  • 您是否将all.xlsx 文件包含在您上传到shinyapps.io 的文件中?我建议将文件放在某种data 文件夹中,然后从那里读取
  • 我愿意。我做了你推荐的。我相信问题可能有所不同,并且与这条线有关,它突然创建了一个新的数据框 ft
  • 好的,我找到了,我发布了答案

标签: r shiny shinyapps


【解决方案1】:

好的,我发现我必须放置它

ID<-c(1,2,3,4)
    Name<-c("j","dd","ff","fcf")
    Language<-c("en","fr","gr","gh")
    Country<-c("EN","FR","GR","GRE")
    Topic<-c("sc","sc","ghgf","vb")
    Follow<-c(34,56,76,76)
    Social<-c("Facebook","Facebook","Twitter","Twitter")
    all2<-data.frame(ID,Name,Language,Country,Topic,Follow,Social) 

shinyApp()之前

【讨论】:

    猜你喜欢
    • 2018-02-03
    • 2020-04-16
    • 2016-06-15
    • 2017-09-05
    • 2014-08-09
    • 2019-04-24
    • 2020-06-01
    • 2020-09-30
    • 2019-09-03
    相关资源
    最近更新 更多