R闪亮的映射输出到输入

时间:2018-05-14 13:33:30

标签: r shiny

我正在构建我的第一个闪亮的应用程序,我遇到了一些我无法理解的困难

我的代码想要从用户那里获取输入 - 添加一个然后打印输出 请暂时忽略单选按钮 -

    ui <- shinyUI(fluidPage(

  titlePanel("alpha"),

    sidebarPanel(numericInput("expn", 
                              "Please enter total number of reports received", 1,
                              min = 0,
                              max = 1000000
    ),
     radioButtons(inputId = "'QC_Type'", label = "QC Type", 
                 choices = c("Overall", "Solicited", "Spontaneous", 
                             "Clinical Trial","Literature" ),


    mainPanel(
      textOutput("results"))

    ))))





  server <- function (input, output) {
    output$results <- renderText(
    { print(1 +(Input$expn))
  }
  )
}

shinyApp(ui = ui, server = server)

运行代码时,我无法看到任何输出。

感谢您的时间:)

1 个答案:

答案 0 :(得分:2)

这是因为您的mainPanel位于何处。它应该遵循sidebarPanel。另外,我建议使用as.character()而不是print(),除非您真的想在控制台上打印输出。

以下是更正后的代码:

ui <- shinyUI(fluidPage(
  titlePanel("alpha"),

  sidebarPanel(
    numericInput(
      "expn",
      "Please enter total number of reports received",
      1,
      min = 0,
      max = 1000000
    ),
    radioButtons(
      inputId = "'QC_Type'",
      label = "QC Type",
      choices = c(
        "Overall",
        "Solicited",
        "Spontaneous",
        "Clinical Trial",
        "Literature"
      )
    )
  ),
  mainPanel(textOutput("results"))
))

server <- function (input, output) {
  output$results <- renderText({
    as.character(1 + (input$expn))
  })
}

shinyApp(ui = ui, server = server)

我建议在缩进代码时使用好的做法。它使事情更容易阅读,并找到括号和括号的位置。