我有一个工作的R应用程序,我想使用Shiny在线提供.我的应用程序接收文件作为输入,因此客户端通过ui.R上传文件.server.R接收文件,然后我想调用我的应用程序.但是,当我使用source()时,myApp不知道我在server.R中收到的文件并抛出错误:找不到对象.这是server.R的代码
shinyServer(function(input, output) {
output$contents <- renderTable({
inFile <- input$file1
if (is.null(inFile))
return(NULL)
else{
tdata <- as.matrix(read.table(inFile$datapath))
head(tdata, n = 2)
source("./CODE/run_myApp.r")
}
})
})
Run Code Online (Sandbox Code Playgroud)
但是,myApp不包含tdata(在我当前的应用程序中需要作为输入文件).
基于多个 stackoverflow 问题,我尝试构建这个应用程序,其中包含两个操作按钮,第一个显示数据表,第二个应该打开另一个源应用程序,但实际上,没有任何变化,但在全局环境中,所有列表、函数和数据框都是反映。使用的代码。
#UI.R
library(shiny)
library(shinydashboardPlus)
library(DT)
library(readxl)
library(dplyr)
library(formattable)
library(shinydashboard)
library(shinyjqui)
library(shinyjs)
library(shinythemes)
library(markdown)
title <- "emblem"
ui = fluidPage(theme=shinytheme("superhero"),
dashboardPage(dashboardHeader(title = title, titleWidth = 200),
dashboardSidebar(selectInput("listofitems","Items List",c("Home","Group","Clients"), selected = "Home")),
dashboardBody(
useShinyjs(),
uiOutput("ui_myHome"))))
Run Code Online (Sandbox Code Playgroud)
#SERVER.R Clientsbutton<-fluidPage(theme=shinytheme("yeti"),
DT::dataTableOutput("mytable"))
shinyServer(function(input, output, session){
output$mytable = DT::renderDataTable({
mtcars
})
output$ui_myHome<-renderUI({
if (input$listofitems == 'Home'){(fluidPage(
widgetUserBox(title = "Clients",
shiny::actionButton(inputId='clientsmainbuttonId', label="Click here"),
type = 2, src = "https://adminlte.io/themes/AdminLTE/dist/img/user7-128x128.jpg", color = "yellow"),
widgetUserBox(title = "Group",
shiny::actionButton(inputId='GroupbuttonId', label="Click here"),
type = 2, src = "https://adminlte.io/themes/AdminLTE/dist/img/user7-128x128.jpg", color = …Run Code Online (Sandbox Code Playgroud)