I was wondering whether it is possible to start a shiny app with an argument being passed to it.
For example, say I want to do a histogram of some data set. If I know the data set ahead of time then I can save it in the corresponding directory and source it in once the app is running. But what if I don't know what data set a user might want to use?
I have actually thought of 2 so-so solutions:
1) I can have a small wrapper routine in R that first writes the data to some temp directory, then within shiny I can use scan or read. The reason I don't like this is that I want the routine to run on other peoples computers, irrespective of their folders and operating system, and I am sure this won't work everywhere.
2) Similar to the first solution, except I use dump("data","clipboard)
in R and then source("clipboard")
in shiny. Again, this works fine on my computer but I am afraid it won't necessarily work on others.
So my question, is there a more elegant solution that can be relied upon to work on (almost) all computers?
Here is a simple example of the "copy to clipboard" idea: say i want to display a scatterplot in Shiny. First i write a routine in R:
shinyPlot <- function (x)
{
dump("x","clipboard")
runApp("c:/r/shiny/test")
}
Now I have ui.R
shinyUI(fluidPage(
sidebarLayout(
sidebarPanel(),
mainPanel(
plotOutput("plot")
)
)
))
and server.R
shinyServer(function(input, output) {
data <- reactive({
source("clipboard")
x
})
output$plot <- renderPlot({
plot(data())
})
})
Now I can run in R
shinyPlot(faithful)
and this works fine on my computer. But as I said, i am not sure that it would work on all computers. At any rate, is there is a more elegant solution?