Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 闪亮的UI:保存输入中的更改_R_Shiny - Fatal编程技术网

R 闪亮的UI:保存输入中的更改

R 闪亮的UI:保存输入中的更改,r,shiny,R,Shiny,我有一个相当大的问题。我正在尝试运行一个有很多不同设置的程序,这些设置可以在ui中设置。在我的情况下,用户可能需要使用相同的设置多次运行程序。我的问题是,如果刷新或重新启动UI,所有内容都将设置为默认值。例如: numericInput("1", label = h4("...."), 4, min=1,

我有一个相当大的问题。我正在尝试运行一个有很多不同设置的程序,这些设置可以在ui中设置。在我的情况下,用户可能需要使用相同的设置多次运行程序。我的问题是,如果刷新或重新启动UI,所有内容都将设置为默认值。例如:

numericInput("1", 
            label = h4("...."),
                                        4,
                                        min=1, 
                                        max=100, 
                                        step=1 
                                        ),
                           br(),
                           numericInput("2", 
                                        label = h4("..."),
                                        1000000,
                                        min=1, 
                                        max=100000000, 
                                        step=1
                                        )
如果我将NumericiInput“1”设置为7,然后重新运行该程序,则默认值为4。由于我有很多这样的设置,这可能是一个相当大的问题。所以我的问题是:“有没有办法保存我所做的更改?”


谢谢:)

以下是如何使用户输入在会话中保持一致的POC

DPUT和DGET是使it工作的两个命令。因此,您将得到一个存储输入变量值的本地文件。这里我只是让输入$dataset变量保持一致。我认为如果你有更多的变量,你可以使用更高级的命令,甚至数据库。。但这对一个人来说是相当容易的

由于我在server.R和ui.R之间反复使用了几次,我可能需要在开始时通过命令行初始化文件,或者甚至在代码中构建一些逻辑文件来检查文件是否存在,如果不存在,则使用一些默认值创建一个新文件

服务器.R

shinyServer(function(input, output) {

  datasetInput <- reactive({
    switch(input$dataset,
           "rock" = rock,
           "pressure" = pressure,
           "cars" = cars)
  })

  output$summary <- renderPrint({
    dataset <- datasetInput()
    summary(dataset)
    dput(input$dataset, "inputdata_dataset")
  })

  output$view <- renderTable({
    head(datasetInput(), n = input$obs)
  })
})

这是一个棘手的问题。最好有一个客户端解决方案。HTML5允许使用本地存储。有很多javascript库都有简单的api来实现这一点。我将其中一个包裹起来作为概念证明:

devtools::install_github("johndharrison/shinyStorage")
library(shinyStorage)
library(shiny)

runApp(
  list(
    ui = fluidPage(
      addSS(),
      uiOutput("textExample")
      )
    , server = function(input, output, session){
      ss <- shinyStore(session = session)
      output$textExample <- renderUI({
        myVar <- ss$get("myVar")
        if(is.null(myVar)){
          textInput("textID", "Add some text to local storage")
        }else{
          textInput("textID", "Add some text to local storage", myVar)          
        }
      })

      observe({
        if(!is.null(input$textID)){
          if(input$textID != ""){
            ss$set("myVar", input$textID)
          }
        }
      })
    }
    )
  )
devtools::install_github(“johndharison/shinyStorage”)
图书馆(shinyStorage)
图书馆(闪亮)
runApp(
名单(
ui=fluidPage(
addSS(),
uiOutput(“文本示例”)
)
,服务器=功能(输入、输出、会话){

对不起,我花了一些时间。谢谢你的回答

我找到了一个解决方法(我将只发布代码的相关部分)。我使用conditionalpanel找到了解决方案。在我的应用程序中,用户必须在开始计算之前定义设置,并且首先保存这些设置是至关重要的(各种原因,主要是再现性)。因此,我为计算中的每个步骤创建了一个选项卡面板,我非常简单的解决方案是,每个选项卡面板都依赖于“保存”按钮。结果是,用户在未保存设置之前甚至无法启动计算

shinyUI(navbarPage(title=div(img(src="---", height=72, width=72, align="left")), theme ="bootstrap.css", fluid=T,




                 tabPanel("Startseite",
tags$head(tags$script(HTML('
      Shiny.addCustomMessageHandler("jsCode",
        function(message) {
          console.log(message)
          eval(message.code);
        }
      );
    '))),

                        actionButton("Ja",
                                     label="Neue Berechnung beginnen",
                                     icon("upload",lib="font-awesome")),

                        actionButton("Nein",
                                     label="Bestehende Berechnung laden",
                                     icon("upload",lib="font-awesome"))),

               tabPanel("Einstellungen", progressInit(),

                        conditionalPanel(condition="input.Ja > 0",

                                         wellPanel(actionButton("save",
                                                                label="Einstellungen speichern",
                                                                icon("save",lib="font-awesome")
                                                                ),
                                                   br(),
                                                   br(),
                                                   navlistPanel("Einstellungen",



tabPanel("Interne Kalibrierung",
     conditionalPanel(condition="input.save> 0",

                      wellPanel(actionButton("freqbutton", "Frequenzschätzung durchführen"),
                                plotOutput("freqPlot")
                                ),


                                      wellPanel(actionButton("intthresbutton", "Berechnung der internen Threshold"),
                                                dataTableOutput("IntTable")
                                                ))


     ),

最糟糕的情况是,每次用户与
输入$
交互时,更新数据库/本地文件中一致且可在不同会话之间访问的相应选择?一个选项是在URL中记录输入值,用户可以将其另存为书签。有关如何实现此功能的更多详细信息,请参阅我对的回答。如果您在本地为应用程序提供服务,则每次都必须使用相同的端口号调用
runApp
,URL才能有效。谢谢!我将尝试一下,稍后与大家分享我的解决方案或我的失败。这对多个用户不起作用。这假设应用程序有一个全局用户。@jdson,可能使用文件名前缀
username\uu
?你有什么建议吗?@B.Mr.W.这是可能的,但我想你需要某种日志系统
shinyUI(navbarPage(title=div(img(src="---", height=72, width=72, align="left")), theme ="bootstrap.css", fluid=T,




                 tabPanel("Startseite",
tags$head(tags$script(HTML('
      Shiny.addCustomMessageHandler("jsCode",
        function(message) {
          console.log(message)
          eval(message.code);
        }
      );
    '))),

                        actionButton("Ja",
                                     label="Neue Berechnung beginnen",
                                     icon("upload",lib="font-awesome")),

                        actionButton("Nein",
                                     label="Bestehende Berechnung laden",
                                     icon("upload",lib="font-awesome"))),

               tabPanel("Einstellungen", progressInit(),

                        conditionalPanel(condition="input.Ja > 0",

                                         wellPanel(actionButton("save",
                                                                label="Einstellungen speichern",
                                                                icon("save",lib="font-awesome")
                                                                ),
                                                   br(),
                                                   br(),
                                                   navlistPanel("Einstellungen",



tabPanel("Interne Kalibrierung",
     conditionalPanel(condition="input.save> 0",

                      wellPanel(actionButton("freqbutton", "Frequenzschätzung durchführen"),
                                plotOutput("freqPlot")
                                ),


                                      wellPanel(actionButton("intthresbutton", "Berechnung der internen Threshold"),
                                                dataTableOutput("IntTable")
                                                ))


     ),