如何更改 csv 中的值使用闪亮的滑动条?

问题描述

(并提前感谢您的帮助)

我正在尝试在我的 Shiny 应用程序中创建一个滑动条。该条必须能够在建模过程中更改氯的百分比值。我的意思是您使用可以在 csv 中找到的固定值来启动模型。然后,bar要改变这个值,当然还要改变建模结果。

我为 UI 和 SERVE 编写了代码

界面

            mainPanel(
              fluidRow(
                  column(12,h3("Modificacio de Clor"),#title
                      p("Tria de percentatge per a modificar el Clor a la xarxa"),#subtitle
                      sliderInput(inputId = "clor_modif",label = "% Clor:",min = -1,max = 1,value = 
                                  0.75,step = 0.05,round = T),#sliderInput with relevant information of 
                                                                 #my bar 
                     )
                  )
               )
            
    ),```

```shinyServer(function(input,output) {

observe({
     #Database where the parameter of chlorine is saved
      simulation_parameters_zona <- read.csv("./data/simulation_parameters_zona.csv",header = TRUE) 
     #The parameter is in 8th file
      simulation_parameters_zona <- simulation_parameters_zona[8,]
     
     #I want the slidebar change the value and the value will be recorded in the csv. 
     #(simulation_parameters_zona). Because when we re-run the modeling,the shiny app takes into account 
     #the new value,and then changes de result of the model.
      
      val <- input$clor_modif
      updateSliderInput(session,val,value = simulation_parameters_zona$dades2*val)
      
    })
})```

Actually,I tried several times how I Could attach the bar to the file,but I can't... I'm sorry if the question is dumb (I'm sure about it). I'm a beginner with Shiny...




***Thank you very much for your help!***

解决方法

我终于解决了我的问题......比我想象的要容易,我开始解释! :)

问题是我无法调用数据集 Simulation_parameters_zona 的第 8 行,因为我使用了错误的命名法!

我的问题的正确答案是:

 observe({
      simulation_parameters_zona <- read.csv("./data/simulation_parameters_zona.csv",header = TRUE)
      simulation_parameters_zona$dades2[8] <- input$clor_modif
      write.csv(simulation_parameters_zona,"./data/simulation_parameters_zona.csv",row.names = FALSE)
      print(input$clor_modif)
    })

这允许侧边栏将数字更改为模拟_参数_zona.csv 中的输入,并且每次有人更改该栏时它都会更改模拟。

我希望这可以帮助其他人! :)

干杯!