r 闪亮显示数据集中的特定行

r shiny display specific rows from a dataset

抱歉,我重新发布了这个问题,因为版主没有取消对之前发布的这个问题的保留 () 我正在尝试在 r shiny 中编写一个脚本,使得

Step 1) Accept input from the user
Step 2) Check if that value exist in the dataset (iris)
Step 3) if that value exists then display that value and another value from a different column associated with that value.

例如,考虑鸢尾花数据集

头部(虹膜)

     Sepal.Length Sepal.Width Petal.Length Petal.Width Species
       5.1         3.5          1.4         0.2  setosa
       4.9         3.0          1.4         0.2  setosa
       4.7         3.2          1.3         0.2  setosa
       4.6         3.1          1.5         0.2  setosa
       5.0         3.6          1.4         0.2  setosa
       5.4         3.9          1.7         0.4  setosa

用户输入一个值(5.1),闪亮检查Sepal.Length列中是否存在该值,如果存在则显示该值(5.1)和相应的物种值(Setosa)。如果该值不存在,则闪亮显示未找到。

这就是我到目前为止所做的。需要一些指点。

UI.r

   shinyUI(fluidPage(
     titlePanel("Test Case"),
     sidebarLayout(
       sidebarPanel((""),
             textInput("mrnnumb", "Enter Sepal Length",""),
             submitButton("Ok")),
                     mainPanel(("Results"),
             textOutput("yn"))
     )

     ))

server.r

 data(iris)

 library(shiny)

 shinyServer(
   function(input, output, session)
   {

    output$yn = reactive({ifelse((input$mrnnumb) %in% iris$Sepal.Length, "Found","Not Found") })
      }
    )

这样做:

您需要在 ui 中添加另一个 textOutput,然后在服务器中获取反应器以允许您访问它。

library(shiny)

ui <- fluidPage(
  titlePanel("Test Case"),
  sidebarLayout(
    sidebarPanel((""),
                 textInput("mrnnumb", "Enter Sepal Length",""),
                 submitButton("Ok")),
    mainPanel(("Results"),
              textOutput("yn"),
              textOutput("species"))
  )

)




server <- function(input, output) {

  data(iris)

    output$yn = reactive({ifelse((input$mrnnumb) %in% iris$Sepal.Length, "Found","Not Found")})

    output$species = reactive({

      n <- input$mrnnumb
      myspecies <- iris[(iris$Sepal.Length == n),5]
      return(myspecies)
  })

  }


shinyApp(ui = ui, server = server) #this runs the app

这给你:

当您输入 5.1 时,有多个选项 - 并且全部返回。