I want to send my dataframe from function summ() to server function. I am performing all operations in summ() function{operationsi am not showing} and at last dataframes is prepared. In server, I want to plot two separate graphs using those dataframes named df and df1.
Can anybody help me how to send these dataframes from summ function into shiny.
library(shiny)
library(ggplot2)
ui<-fluidPage(
sidebarLayout(
sidebarPanel(
sliderInput(inputId = "Y",label = "Price", value = 2, min =1,max = 6),
sliderInput(inputId = "d_km",label = "Distance", value = 5, min =1,max = 20),
sliderInput(inputId = "fact",label = "Multiplication", value = 2, min =1,max = 5),
actionButton(inputId = "button", label = "Simulate")
),
mainPanel(
plotOutput("X"),
plotOutput("HH")
)
)
)
summ<-function(Y,d_km,fact)
{
### code ###
df <- data.frame("x"=x,"y1"=y1,"y2"=y2)
df1<- data.frame("obj"=obj_vector)
returns <- list(plot = df, plots=df1)
}
server<-function(input, output,session){
default_list <- list(plot = df, plots=df1)
# daf <- data.frame()
rv<-reactiveValues(data=default_list)
rv$data <- reactive(summ (input$Y, input$d_km, input$fact))
frame <- eventReactive(input$button, {
returned <- rv$data()
cost <- returned$plot
})
frame1 <- eventReactive(input$button, {
returned <- rv$data()
coost <- returned$plots
})
output$X <- renderPlot({
ggplot(frame(), aes(x)) + # basic graphical object
geom_line(aes(y=y1), colour="red") + # first layer
geom_line(aes(y=y2), colour="green")+
xlab("Bag_no.")+ylab("Price in USD")+
geom_text(aes(y=y1,label=y1),size=3,angle=45)
})
output$HH <- renderPlot({
ggplot(frame1(),aes(x=seq(1,runs,1),y=obj_vector))+geom_line(colour="blue")+
xlab("Simulation_run")+ylab("Objective_value")
# grid.arrange(p1,p2,ncol=2)
})
}
shinyApp(ui = ui, server = server)
Appreciate your help.
serveryou definedefault_listusingdfanddf1which are not defined not before nor after in your global or server's local environments. Also you don't actualy usedefault_listeven after assigning it torvusingreactiveValues(), so I don't see the goal ofdefault_listin your App. You can replace that one like following, if you still need it in your program:frameandframe1are functions and they are assumed to return smth. So you can change it like this:output$HHvisualization you use variablerunswhich is not defined anywhere in your App, you need to define it beforehand to use (maybe you have defined it in code that you don't show, but now it causes error).output$HHyou usey = object_vector, but insumm()you assign it todata.frame('obj' = object_vector), so you need to change your code like this:Or in
summ():Either in
output$HH: