For hours I've been struggling. My Shiny App
is supposed to display some variables that I have in my R environment. It works all works fine but when I deploy it to the web I get errors like:
Error: object 'df1' not found
How can I add df1
and my other data frames so they can be packaged as part of the Shiny App
when it is deployed?
Please help. Here's my sample code:
server.R
library(shiny)
shinyServer(function(input,output){
output$datasets <- renderTable({
switch(input$choice,
"1" = as.data.frame(df1)
"2" = as.data.frame(df2) })
}))
UI.R
shinyUI(
fluidPage(theme = "bootstrap.css",
sidebarPanel(
conditionalPanel(
condition = "input.theTab == 'datasets' ",
h3('Display Sample Data'),
selectInput("choice", "Selection", choices = c("Group1"=1,"Group2"=2)),
)),
mainPanel(
tabsetPanel(
tabPanel( "datasets", tableOutput("datasets"), value = 'datasets'),
id = "theTab"))
)
Your title asks about importing a data frame into shiny. That can be done by storing the data frame either as a binary file using the save() function or a csv file using write. csv() and having the shiny app read it in using load() for a binary file or read. csv() for a csv file.
You can create a standalone shiny app, that runs on computers WITHOUT needing to install R nor any library.
In recent shiny versions you can include variables in a global.R file, and those will be available for ui and server. Take a look at the scoping rules here:
http://shiny.rstudio.com/articles/scoping.html
Finally figured out the solution!! basically I was supposed to load my workspace at the top of the UI.R
file. This way:
attach("myWorkspace.RData")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With