【发布时间】:2020-06-18 10:54:55
【问题描述】:
我没有在其他地方看到这个问题得到明确的回答。我想要一个“textInput”框,用户可以在其中输入国家名称“Argentina”。根据该输入,在代码的服务器部分,我想按该国家/地区名称对预加载的数据框进行子集化。
有人可以帮助我如何做到这一点吗?非常感谢。
以下是使用 mtcars 作为示例数据的代码。
# Some Sample data to run app using mtcars
mtcars$Primary<- rownames(mtcars)
mtcars$Area <- "Argentina"
mtcars$Y2016<- mtcars$mpg
mtcars$Element <- "Gross Production Value (constant 2004-2006 million US$)"
# Defining UI ----
ui <- pageWithSidebar(
# App title ----
headerPanel("Subsector Selection Tool"),
# Sidebar panel for inputs ----
sidebarPanel(
# Input: Country name
textInput("country", "Please enter country name", "")#,
),
# Main panel for displaying outputs ----
mainPanel("")
)
# Use user input (country name) to subset desired dataframe.
server <- function(input, output) {
#Trying to make user inputed country name into an object to be used in "reactive" code below, which in turn is be used to make dataset for graphing
country_interest <- reactive({
paste(input$country)
})
#Here I am trying to make the data analysis code run and create desired dataset for graphing, and
subsetting for country selected by user
Value_c_e_PRIM_x <- reactiveValue({
Value_c <- Value[which(Value$Area==country_interest),]
})
【问题讨论】: