【问题标题】:Pass URL parameter to shiny plot function将 URL 参数传递给闪亮的绘图函数
【发布时间】:2016-08-13 00:13:36
【问题描述】:

按照this 的回答,我正在尝试创建一个应用程序,该应用程序将根据我将通过 URL 传递给应用程序的值输出绘图

library(shiny)

shinyApp(
  ui = fluidPage(
    mainPanel(
      plotOutput("plot")
    )
  ),
  server = function(input, output, session) {
    observe({
      query <- parseQueryString(session$clientData$url_search)
      if (!is.null(query[['text']])) {
        n <- query[['text']]
      }
    })
    output$plot <- renderPlot({
      # Add a little noise to the cars data
      plot(cars[sample(nrow(cars), n), ])
    })
  }
)

但我不知道应该在哪里/如何存储/传递变量 n 的值,以便将其从 observe() 转移到 renderPlot()

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    试试这个。请注意n 被定义为每个会话的全局变量,并注意全局赋值运算符&lt;&lt;-

    library(shiny)
    
    shinyApp(
        ui = fluidPage(
            mainPanel(
                plotOutput("plot")
            )
        ),
        server = function(input, output, session) {
            n <- 5
            observe({
                query <- parseQueryString(session$clientData$url_search)
                if (!is.null(query[['text']])) {
                    n <<- query[['text']]
                }
            })
            output$plot <- renderPlot({
                # Add a little noise to the cars data
                plot(cars[sample(nrow(cars), n), ])
            })
        }
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-28
      • 1970-01-01
      • 2019-08-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多