【问题标题】:How to get the value in uioutput in ui.R and send it back to server.R?如何在ui.R中获取uioutput中的值并将其发送回server.R?
【发布时间】:2015-12-25 03:42:50
【问题描述】:

ui.R,我输入:

uiOutput("singlefactor")

server.R,我有:

  output$singlefactor <- renderUI({
    selectInput("sfactor", "Feature selection:", names(datatable()))
  })

使用这些,我可以在选择菜单中显示 data.frame datatable() 的列名。我接下来要做的是:

假设datatable() 中的列名是abcd。我从ui.R 中选择a,然后将a 发送回服务器,以便我可以使用仅包含a 的datatable() 的子集进行下一次计算。

所以,我的问题是:我怎样才能回信给server.R

【问题讨论】:

  • 只需要创建一个变量来监听input$sfactor。像my_var &lt;- reactive({if (is.null (input$sfactor)) return(NULL) else return(input$sfactor)}) 这样的东西。然后你可以在任何地方使用my_var() 调用该变量。或者,只需使用input$sfactor

标签: r shiny


【解决方案1】:

该值将像任何其他输入一样可用,例如

library(shiny)

runApp(list(ui=shinyUI(fluidPage(
  sidebarLayout(
    sidebarPanel(
      uiOutput("singlefactor")
    ),
    mainPanel(
      plotOutput("distPlot")

    )
  )
))
,
server=shinyServer(function(input, output) {
     output$singlefactor <- renderUI({
    selectInput("sfactor", "Feature selection:", names(mtcars))
  })
  output$distPlot <- renderPlot({plot(mtcars[,input$sfactor])})

})
))

您创建了一个名为“sfactor”的 UI 元素,因此您可以使用 input$sfactor 获取值

【讨论】:

  • 是的,它完全有效!多谢。我对闪亮是全新的。所以也许有很多问题对我来说很难。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-02-01
  • 2017-10-22
  • 1970-01-01
  • 2014-06-05
  • 2022-01-10
  • 1970-01-01
  • 2017-03-06
相关资源
最近更新 更多