【发布时间】:2018-04-05 14:55:03
【问题描述】:
您好,我需要通过输入过滤数据的帮助。单独选择输入可以正常工作。我尝试类似
output$tbl<-renderTable({subset(data,data$country==input$countryIn||
data$code==input$code)})
但它不起作用。我希望用户选择国家,然后可以将代码写入文本输入并减少数据区域。
ui.R
library(shiny)
shinyUI(fluidPage(
titlePanel("This is my website"),
sidebarLayout(
sidebarPanel(uiOutput(outputId="country"),textInput(inputId="code",label="writte code")),
mainPanel(tableOutput(outputId="tbl"))
))
)
server.R
library(shiny)
id<-1:6
country<-c("Germany","UK","USA","Poland","UK","UK")
code<-c(255,124,234,751,124,326)
data<-data.frame(id,country,code)
shinyServer(
function(input,output)
{
output$country<-renderUI({selectInput(inputId ="countryIn",label="Choose country",choices=unique(data$country))})
output$tbl<-renderTable({subset(data,data$country==input$countryIn)})
})
【问题讨论】: