我有一个名为“ a2”的数据集。样本数据
select dim1, dim2, dim3, dim4, dim5, dim6, dim7,
t1.* except (dim1, dim2, dim3, dim4, dim5, dim6, dim7),
t2.* except (dim1, dim2, dim3, dim4, dim5, dim6, dim7),
t3.* except (dim1, dim2, dim3, dim4, dim5, dim6, dim7)
from t1 full join
t2
using (dim1, dim2, dim3, dim4, dim5, dim6, dim7) full join
t3
using (dim1, dim2, dim3, dim4, dim5, dim6, dim7);
我想使用三个选项卡“筛选器值”,“最近的商店”和“最近的客户端”来开发闪亮的应用程序。因此,无论用户选择什么作为输入,它都应显示输入的所有行。
因此在“过滤器值”选项卡中 例如,如果我选择CID 3,那么它应该只提取具有CID3的行。
因此在“最近的商店”标签中 例如,如果我选择商店X,那么它应该只提取具有商店X的行。
inner join
但是,在“最近的客户端”标签中,我想要两个过滤器,一个是CID,另一个是距离。
因此,如果选择CID1和最小距离2,则应该只给我一行。
我的输出正在“标签值”和“最近的存储”选项卡中生成a2的所有数据。我陷入了“最近的客户”标签
谢谢
传单
数据框是
样本数据如下
CID Store Distance
1 X 2
2 Y 3
2 S 5
1 A 1
3 B 10
图书馆(传单)
shinyApp(
ui = fluidPage(
titlePanel("Lat Long Address Mapping in R"),
fluidRow(
mainPanel(
tabsetPanel(type = "tabs",
tabPanel("FilterValue",
selectInput('InputID', 'ID', choices=NULL, selected=NULL),
),
tabPanel("Nearest Store",
selectInput('InputStore', 'ID', choices=NULL, selected=NULL),
),
tabPanel("Nearest Client",
selectInput('InputCustomer', 'ID', choices=NULL, selected=NULL),
)
))))
,
server = function(input, output,session) {
output$FilterValue<- renderDataTable(a2)
updateSelectizeInput(session, 'InputID',
choices = a2$CID,
server = TRUE)
updateSelectizeInput(session, 'InputStore',
choices = a2$Store,
server = TRUE)
updateSelectizeInput(session, 'InputCustomer',
choices = a2$CID,
server = TRUE)
output$Nearest Client<- renderDataTable({
paste(input$InputCustomer)
})
})
当我独立运行此程序时
ID Lat Long Address
1 12.904249 77.70253 1/2 CA
2 21.221475 72.81281 2/3 DC
3 23.039251 72.58388 3/5 HJ
答案 0 :(得分:1)
您可以将数据保存为反应性数据,并使用dplyr对其进行过滤
a2 %>% filter(CID == input$InputID & Distance == input$InputCustomer)
这将在最后一个选项卡中执行您想要的操作。您提供的代码还存在一些问题,例如您想要呈现的数据表没有输出等等。我试图在构建它的方式上不要做太多改变,但是有更好的方法来构建应用程序。以下是我认为您要求的工作示例:
a2 <- data.frame(CID = c(1,2,2,1,3),
Store = c("X", "Y", "S", "A", "B"),
Distance = c(2,3,5,1,10), stringsAsFactors = FALSE)
library(shiny)
library(dplyr)
library(DT)
ui <- fluidPage(
fluidRow(
mainPanel(
tabsetPanel(type = "tabs",
tabPanel("FilterValue", value = "filtervalue",
selectInput('InputID', 'ID', choices=NULL, selected=NULL),
dataTableOutput("out1")
),
tabPanel("Nearest Store", value = "neareststore",
selectInput('InputStore', 'ID', choices=NULL, selected=NULL),
dataTableOutput("out2")
),
tabPanel("Nearest Client", value = "nearestclient",
selectInput('InputCustomer', 'ID', choices=NULL, selected=NULL),
dataTableOutput("out3")
)
)))
)
server <- function(input, output, session) {
filtout <- reactive({
a3 <- a2 %>% filter(CID == input$InputID)
return(a3)
})
output$out1 <- DT::renderDataTable(datatable(filtout(), options = list(searching = F,
pageLength = 20,
lengthMenu = c(5, 10, 15, 20),
scrollX = T,
autoWidth = TRUE
)))
storeout <- reactive({
a3 <- a2 %>% filter(Store == input$InputStore)
return(a3)
})
output$out2 <- DT::renderDataTable(datatable(storeout(), options = list(searching = F,
pageLength = 20,
lengthMenu = c(5, 10, 15, 20),
scrollX = T,
autoWidth = TRUE
)))
custout <- reactive({
a3 <- a2 %>% filter(CID == input$InputID & Distance == input$InputCustomer)
return(a3)
})
output$out3 <- DT::renderDataTable(datatable(custout(), options = list(searching = F,
pageLength = 20,
lengthMenu = c(5, 10, 15, 20),
scrollX = T,
autoWidth = TRUE
)))
updateSelectizeInput(session, 'InputID',
choices = a2$CID,
server = TRUE)
updateSelectizeInput(session, 'InputStore',
choices = a2$Store,
server = TRUE)
updateSelectizeInput(session, 'InputCustomer',
choices = a2$Distance,
server = TRUE)
output$nearestclient<- renderDataTable({
paste(input$InputCustomer)
})
}
shinyApp(ui, server)
新信息:
所以我发现问题是cardDB.postitron。我将地图更改为通常使用的地图。另外,我还必须剥离一些UI才能获得原理性工作,并且未提供adress变量,但这应构成您所需的基础。
library(shiny)
library(leaflet)
ui <- fluidPage(
fluidRow(
mainPanel(
tabsetPanel(type = "tabs",
tabPanel(title = "Map",
leafletOutput("map")
)))))
server <- function(input, output, session) {
output$map <- renderLeaflet({
leaflet(a) %>%
addProviderTiles(providers$Esri.WorldGrayCanvas,
options = providerTileOptions(noWrap = TRUE)) %>%
addMarkers(lng = ~Long, lat = ~Lat,
popup = ~address)
})
}
shinyApp(ui, server)