0
votes

I have the following in server.R

library(shiny)

# Load the ggplot2 package which provides
# the 'mpg' dataset.
library(ggplot2)

# Define a server for the Shiny app
shinyServer(function(input, output) {

# Filter data based on selections
output$table <- renderDataTable({
data <- as.data.frame(98,99,34)
names(data) <- "Projection"
data
})

And the following in ui.R library(shiny)

# Define the overall UI
shinyUI(
fluidPage(
titlePanel("Basic DataTable"),



# Create a new row for the table.
fluidRow(
  dataTableOutput(outputId="table")
)    
)  
)

Is it possible to add a column to the data dataframe that is a numericInput where the user can modify the projections if they don't agree with it. Something like this:

Projection Your Projection

98 |_____________| <- Numeric Input goes in there, then the projection updates

1

1 Answers

1
votes

This is not exactly what you are looking for, but it should work. I also added a global.r so that you have dataframe that can be leveraged over both ui.r and server.r

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

It is important to note the <<- will apply to a dataframe outside of the function, this allows you to edit global dataframes.