0
Shiny Appユーザーがアップロードした.Rdata
ファイルからいくつかのオブジェクトにアクセスして使用したいとします。 .Rdata
に格納されている複数のオブジェクトにアクセスするという簡単な呼び出しによって、global.R
のload()
を呼び出すことは可能ですが、.Rdata
ファイルがアップロードされたときにアクセスして使用する方法を理解できません。Shinyの.RDataファイル内の複数のオブジェクトを読み込んで使用する
再現例えばその模倣this related question where the .Rdata
file contains only one object.次のエラーメッセージを与えるxyz.RData
とx.RData
なくアップロードするときこれが動作
library(shiny)
# Define several objects and store them to disk
x <- rnorm(100)
y <- rnorm(200)
z <- "some text for the title of the plot"
save(x, file = "x.RData")
save(x, y, z, file = "xyz.RData")
rm(x, y, z)
# Define UI
ui <- shinyUI(fluidPage(
titlePanel(".RData File Upload Test"),
mainPanel(
fileInput("file", label = ""),
actionButton(inputId="plot","Plot"),
plotOutput("hist"))
)
)
# Define server logic
server <- shinyServer(function(input, output) {
observeEvent(input$plot,{
if (is.null(input$file)) return(NULL)
inFile <- isolate({input$file })
file <- inFile$datapath
# load the file into new environment and get it from there
e = new.env()
name <- load(file, envir = e)
data <- e[[name]]
# Plot the data
output$hist <- renderPlot({
hist(data)
})
})
})
# Run the application
shinyApp(ui = ui, server = server)
:.RData
3つの異なるオブジェクトので、理想的
Warning: Error in [[: wrong arguments for subsetting an environment
Stack trace (innermost first):
65: observeEventHandler [/Users/.../Desktop/app.R#31]
1: runApp
を再利用されるでしょう、私は反応性要素を作成する解決策を探していますx()
、y()
、z()
はいくつかにまたがって再利用できるrenderXXX()
です。