R闪亮过滤器问题
在我的R Shining项目中执行功能过滤器时遇到问题(不确定这是否是UI或服务器的问题)-->邻居和评论数将无法与房间类型和区域过滤器进行通信 服务器代码R闪亮过滤器问题,r,filter,shiny,R,Filter,Shiny,在我的R Shining项目中执行功能过滤器时遇到问题(不确定这是否是UI或服务器的问题)-->邻居和评论数将无法与房间类型和区域过滤器进行通信 服务器代码 options(shiny.maxRequestSize=30*1024^2) library(shiny) library(leaflet) library(dplyr) # Define server that analyzes the Singapore Airbnb Listings shinyServer(function(in
options(shiny.maxRequestSize=30*1024^2)
library(shiny)
library(leaflet)
library(dplyr)
# Define server that analyzes the Singapore Airbnb Listings
shinyServer(function(input, output) {
# Create an output variable for problem description
output$text <- renderText({
"This project uses the dataset .................FILL OUT LATER........."
})
# Create a descriptive table for NBHD
output$table1 <- renderPrint({
# Connect to the sidebar of file input
inFile <- input$file
if(is.null(inFile))
return("Please Upload A File For Analysis")
# Read input file
mydata <- read.csv(inFile$datapath)
attach(mydata)
# Filter the data for different Room Types and Regions
target1 <- c(input$room_type)
neighbourhood_df <- filter(mydata, room_type %in% target1)
# Create a table for NBHD
table(mydata$neighbourhood)
})
# Create a descriptive table for # of reviews
output$table2 <- renderPrint({
# Connect to the sidebar of file input
inFile1 <- input$file
if(is.null(inFile1))
return("Please Upload A File For Analysis")
# Read input file
mydata1 <- read.csv(inFile1$datapath)
attach(mydata1)
# Filter the data for different Room Type and Region
target3 <- c(input$room_type)
target4 <- c(input$region)
number_of_reviews_df <- filter(mydata1, room_type %in% target3 & region %in% target4)
# Create a table for Rooms
table(mydata1$number_of_reviews)
})
# Create a map output variable
output$map <- renderLeaflet({
# Connect to the sidebar of file input
inFile2 <- input$file
if(is.null(inFile2))
return(NULL)
# Read input file
mydata2 <- read.csv(inFile2$datapath)
attach(mydata2)
# Filter the data for different Room Type and Region
target5 <- c(input$room_type)
target6 <- c(input$region)
map_df <- filter(mydata2, room_type %in% target5 & region %in% target6)
# Create colors with a categorical color function
color <- colorFactor(rainbow(9), mydata2$neighbourhood)
# Create the leaflet function for data
leaflet(map_df) %>%
# Set the default view
setView(lng = 103.8608, lat = 1.2834, zoom = 12) %>%
# Provide tiles
addProviderTiles("CartoDB.Positron", options = providerTileOptions(noWrap = TRUE)) %>%
# Add circles
addCircleMarkers(
radius = 2,
lng= mydata2$longitude,
lat= mydata2$latitude,
stroke= FALSE,
fillOpacity=0.1,
color=color(neighbourhood)
) %>%
# Add legends for different nbhds
addLegend(
"bottomleft",
pal=color,
values=neighbourhood,
opacity=0.5,
title="Singapore Neighbourhood"
)
})
})
library(shiny)
library(leaflet)
library(shinythemes)
# Define UI for application that analyzes the patterns of crimes in DC
shinyUI(fluidPage(
# Change the theme to flatly
theme = shinytheme("flatly"),
# Application title
titlePanel("Patterns of Crimes in Washington DC"),
# Three sidebars for uploading files, selecting Room types and Regions
sidebarLayout(
sidebarPanel(
# Create a file input
fileInput("file","Choose A CSV File Please",
multiple = TRUE,
accept = c("text/csv",
"text/comma-separated-values,text/plain",
".csv")),
# Create a multiple checkbox input for Room Type
checkboxGroupInput("RoomType",
"Room Type:",
c("Private Room","Entire home/apt","Shared room")
),
hr(),
helpText("Please Select The Room type for listing analysis"),
helpText("You Can Choose More Than One"),
hr(),
hr(),
# Create a multiple checkbox input for Regions
checkboxGroupInput("Region",
"Region:",
choices = list("Central Region"= 1,"East Region"= 2,"North Region"= 3,"North-East Region"= 4,
"West Region"= 5)
),
hr(),
helpText("Please Select The Regions You Would Like To Analyze For Listing Patterns"),
helpText("You Can Choose More Than One")
),
# Make the sidebar on the right of the webpage
position = "right",
fluid = TRUE,
# Create two tabs
mainPanel(
hr(),
tabsetPanel(type="tabs",
#Add a tab for Analysis Overview
tabPanel("Analysis Overview", textOutput("text")),
#Add a tab for Room type and Region
tabPanel("Listing Analysis",
#Add two subtabs
tabsetPanel(
tabPanel("Neighbourhood",verbatimTextOutput("table1")),
tabPanel("Number of Reviews",verbatimTextOutput("table2"))
)
),
#Tab for the Leaflet Map
tabPanel("Map", leafletOutput("map", height=630))
)
)
)
))
在UI中调用变量
RoomType
和Region
,但在服务器代码中调用变量input$room\u type
和input$Region
。输入$
正确,但变量名称不同。因此,您基本上是在%NULL中对房间类型%进行筛选
编辑澄清:
在UI中,您有:
# Create a multiple checkbox input for Room Type
checkboxGroupInput("RoomType",
"Room Type:",
c("Private Room","Entire home/apt","Shared room")
)
# Filter the data for different Room Type and Region
target3 <- c(input$room_type)
在服务器中,您有:
# Create a multiple checkbox input for Room Type
checkboxGroupInput("RoomType",
"Room Type:",
c("Private Room","Entire home/apt","Shared room")
)
# Filter the data for different Room Type and Region
target3 <- c(input$room_type)
仅供参考,您的格式很难阅读。您的代码部分被阻止,但部分未被阻止。请在发布时查看预览。另外,可以随意使用编辑按钮进行修复。欢迎访问该网站。感谢adam现在将进行这些更改。我没有附上csv文件,但这是一个新加坡airbnb数据集,这两个数据集的变量是“房间类型”和“区域”。我相信UI变量名是任意的。input
指向UI中的输入对象。因此,input$RoomType
是在复选框GroupInput中选择的值。嗨,Adam,我做了这些编辑,但它似乎仍然没有进行筛选-不确定原因