I am having difficulty implementing this code on a more complicated setup that I have. My goal is to let the user change column values with the projected values rendered from numericInput button. Global.R is not an option as there are many operations placed on the dataset before the final version is reached. I have everything setup other than being able to observe the input$action and change the dataframe when an action occurs.
ui.R
shinyUI(
fluidPage(
titlePanel("Basic DataTable"),
# Create a new row for the table.
fluidRow(
selectInput("select", label = h3("Select box"),
choices = unique(data$Projection),
selected = unique(data$Projection)[1]),
numericInput("num", label = h3("Numeric input"), value = unique(data$Projection)[1]),
submitButton(text = "Apply Changes", icon = NULL),
dataTableOutput(outputId="table")
)
)
)
server.R
library(shiny)
# Load the ggplot2 package which provides
# the 'mpg' dataset.
# Given that you are not plotting this line is
### useless library(ggplot2)
# Define a server for the Shiny app
shinyServer(function(input, output) {
# Filter data based on selections
output$table <- renderDataTable({
data$User_Prediction[data$Projection==input$select] <<- input$num
data
})
})
global.r
data <- as.data.frame(c(98,99,34))
names(data) <- "Projection"
data$User_Prediction <- 0
Data is stored in server.R as such
data <-reactive({
...
...
...
data
})
I am trying to bring in data which is stored in the reactive function into
d <- reactiveValues(dat=data)
I have tried
d <- data()
d <- data
d <- reactiveValues(dat=data)
Is there any way I could access the data, because otherwise your code works.
values <- reactiveValues(dat = data)
in the server. The make anobserveEvent(input$button, values$data[...] <- new_values)
to update it. This is basic stuff is quite well documented at Rstudios site. – Rorschach<<-
is not good. Reactive values are passed by reference so when you use them you only need<-
unlike normal R objects. – RorschachreaciveValues
, sayvalues <- reactiveValues(dat=data)
, you can access from within a reactive context usingvalues$data
. From outside a reactive context, you can used <- isolate(values$data)
, orreactiveValuesToList
– Rorschach