Make an interactive graph that changes based on parameters

Hello, I am trying to create an interactive chart with the code below. I have as input parameters: the standard deviation, the number of realizations and the autocorrelation distance.
table.years is a table containing percentages based on years. I would like my graph to change when these settings change. Would you know how I could go about it please?
I display 5 columns of my table in the same graph, the first column contains the years and the 5 others the percentages.

Here is the part of table.years
x <- read.table(text = " year 1.per.mille 2.per.mille 3.per.mille 4.per.mille 5.per.mille 6.per.mille 7.per.mille 8.per.mille
1 1 Inf Inf Inf Inf Inf Inf Inf Inf
2 2 Inf Inf Inf Inf Inf Inf Inf Inf
3 3 Inf Inf Inf Inf Inf Inf Inf 472
4 4 Inf Inf Inf Inf Inf 472 358 282
5 5 Inf Inf Inf Inf 438 316 240 186
6 6 Inf Inf Inf 472 316 228 170 128
7 7 Inf Inf Inf 358 240 170 124 92
8 8 Inf Inf 472 282 186 128 92 68
9 9 Inf Inf 382 228 148 100 72 54
10 10 Inf Inf 316 186 118 78 58 44
11 11 Inf Inf 266 154 96 64 48 36
12 12 Inf 472 228 128 78 54 40 32
13 13 Inf 408 196 108 66 46 34 26", header = TRUE)
inf is the value assigned when one of the calculations I performed is not feasible

Here is the part of my code that I would like to change :

ui <- fluidPage(
 # Sidebar layout with input and output definitions ---- 
 sidebarLayout( 
       sidebarPanel(
               sliderInput("stdev", h3("standard deviation (kg/m2"), min = 0.01, max = 20, value = 0.5, step = 0.1), 
             fluidRow( 
                   column(3, numericInput(inputId ="nsim", h3("number of realisations"), min=1,max=100, value = 2)) )


server <- function(input, output) { 
output$GraphPlot1 <- renderPlot({

  par(fig=c(0.2,1,0,0.8), mar = c(2,0,0.1,2), new=TRUE)
  ggplot(table.years,aes(table.years[[2]],table.years[[1]]))+geom_line(color="blue", size = 1.5)+geom_line(aes(table.years[[3]],table.years[[1]]),color="black", size = 1.5)+
    geom_line(aes(table.years[[4]],table.years[[1]]),color="green", size = 1.5)+geom_line(aes(table.years[[5]],table.years[[1]]),color="red", size = 1.5)+
    geom_line(aes(table.years[[6]],table.years[[1]]),color="Yellow", size = 1.5)+
    labs(x = "Percent",
         y = "years")


})

Thanks!

I think you need to step away from shiny, and try to make yourself a simple parameter driven plain r script, that lets you get close to the desired goal.
You provided zero mathematics for how your 3 input parameters might lead to one or another table (you just gave us some hardcoded table).
Your ggplot code seems malformed. Recommend you pivot your data long and map aesthetics to prepared variables, rather than hack into fixed column positions.

Wish you well and good luck !

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.