包含多个子应用程序的闪亮应用程序中的文件上传问题

问题描述 投票:0回答:0

我正在尝试拥有一个包含多个闪亮应用程序的闪亮应用程序。每个具有单独的 ui.R 和 server.R 的子应用程序都可以从主应用程序的选项卡面板访问,我为此使用了 shinyAppDir。问题是每个子应用程序独立运行良好,应用程序有文件输入,用户可以在其中上传 CSV 文件,这也适用于每个应用程序。但是当从主应用程序调用时,应用程序正在打开但文件上传不起作用,显示错误。

任何解决方法?
可能是什么原因?

我附上了我的代码的一个小例子。

主应用程序

library(shiny)

ui <- shinyUI(
  navbarPage(
    "My App",
    selected = NULL,
    navbarMenu(
      "Tools",
      tabPanel(
        "testing",
        uiOutput("test")
        
      ),
      tabPanel(
        "Selection Index (sim)",
        uiOutput("simsel")
      )
    )
  )
)

server <- shinyServer(function(input, output, session) {
  
  datapath <- reactiveVal()
  observeEvent(input$file, {
    datapath(input$file$datapath)
  })
  

  observeEvent(input$navbar == "test", {
    output$test <- renderUI({
      # Set an environment variable with the datapath value
      options(my_datapath = input$file$datapath)
      app <- shinyAppDir("dir/testing", options = list(port = 8000))
      app
    })
  })
  
  
  observeEvent(input$navbar == "Selection Index (sim)",{
    output$simsel <- renderUI({
      app2<-shinyAppDir("dir/sim_selindex")
      app2
    })
  })

  })

shinyApp(ui, server)

子应用程序
ui.R

ui <- fluidPage(
  titlePanel("My App"),
  sidebarLayout(
    sidebarPanel(
      textInput("name", label = "Enter your name:"),
      fileInput("file", "CSV File (upload in csv format)", accept=c("text/csv", "text/comma-separated-values,text/plain", ".csv"))
    ),
    mainPanel(
      h4("Hello,"),
      textOutput("greeting"),
      tableOutput("table")
    )
  )
)

服务器.R

server <- function(input, output) {
  
  # Define a reactive that reads in the uploaded CSV file
  csvfile <- reactive({
    req(datapath())
    dt <- read.csv(datapath(), header=TRUE, sep=",")
    dt
  })
  
  # Render a table of the uploaded CSV data
  output$table <- renderTable({
    csvfile()
  })
  
}

非常感谢任何帮助。

我尽我所能,没有数据路径显示
监听http://127.0.0.1:4544

[1] "csvfile 观察调用"
[1]“数据路径:

shiny
© www.soinside.com 2019 - 2024. All rights reserved.