Adjust shiny textoutput

≡放荡痞女 提交于 2020-07-22 08:31:33

问题


Friends, could you help me adjust my output$ind of my code. My executable code is below. I would like to show the excluded industries, which refers to the variable that I called "ind_exclude". I did a textOutput to list these properties. However it is not working. Every help is welcome.

library(shiny)
library(rdist)
library(geosphere)
library(tidyverse)
library(shinyWidgets)
library(shinythemes)

function.cl<-function(df){
  
  #database df
  df<-structure(list(Industries = c(1,2,3,4,5,6,7), 
                     Latitude = c(-23.8, -23.8, -23.9, -23.9, -23.9,-23.4,-23.5), 
                     Longitude = c(-49.8, -49.3, -49.4, -49.8, -49.6,-49.3,-49.1), 
                     Waste = c(526, 350, 526, 469, 285, 433, 456)), class = "data.frame", row.names = c(NA, -7L))
  
  
  coordinates<-subset(df,select=c("Latitude","Longitude")) 
  d<-distm(coordinates[,2:1]) 
  diag(d)<-1000000 
  min_distancia<-as.matrix(apply(d,MARGIN=2,FUN=min))
  limite<-mean(min_distancia)+sd(min_distancia) 
  
  
  search_vec <- function(mat, vec, dim = 1, tol = 1e-7, fun = all)
  which(apply(mat, dim, function(x) fun((x - vec) > tol)))
  ind_exclude<-search_vec(min_distancia,limite,fun=any) #excluded industries
  if(is_empty(ind_exclude)==FALSE){
  for (i in 1:dim(as.array(ind_exclude))){
  df<-subset(df,Industries!=ind_exclude[i])}}
  
  return(list(
    "IND" =  ind_exclude
  ))
  
}

ui <- bootstrapPage(
  navbarPage(theme = shinytheme("flatly"), collapsible = TRUE,
             "Cl", 
             tabPanel("Solution",
                      sidebarLayout(
                        sidebarPanel(
                        
                          h4("The excluded properties are:"),
                          textOutput("ind"),
                        
                          ),
                        mainPanel(
                          tabsetPanel())))))  
                         
server <- function(input, output, session) {

  Modelcl<-reactive({
    function.cl(df)
  })
  
  output$ind <- renderText({
    IND <- data.frame(Modelcl()[[1]])
  })
  
  }

shinyApp(ui = ui, server = server)

How it was:

Thank you very much!

来源:https://stackoverflow.com/questions/61962692/adjust-shiny-textoutput

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!