Issues related to Shiny from RStudio

Hello,

I would like to insert a table and graph when selecting an option defined in Shiny from RStudio. When selecting the option "Select all properties" I would like to show Table1 and Graph1 on the same page. And if I press the option "Exclude properties that produce less than L and more than S" to present just Table2 and Graph2. The codes for generating tables and graphs are after the shiny code.

Shiny code

library (shiny)
ui <- fluidPage (
    
    titlePanel (title = h1 ("Model for the formation of agricultural property clusters", align = "center")),
    
    sidebarLayout (
        sidebarPanel (
            h2 ("Cluster generation"),
            
            radioButtons ("filter1", h3 ("Potential biogas productions"),
                         choices = list ("Select all properties" = 1,
                                        "Exclude properties that produce less than L and more than S" = 2),
                         selected = 1),
        ),
        
        mainPanel (
            textOutput ("nclusters"),
            textOutput ("abran"),
            textOutput ("bio")
                        
            
            
        )))


# Define server logic required to draw a histogram
server <- function (input, output, session) {
    
}

# Run the application
shinyApp (ui = ui, server = server)

Code for generating table and graph 1

###Table 1
dados_tabela <- Reduce(merge, list(dadoscompleto7, abrangencia, soma_biogas))
kable(dados_tabela[order(dados_tabela$cluster, as.numeric(dados_tabela$Propriedade)),c(2,5,1,6,7)], align = "c", row.names = FALSE) %>%
  kable_styling(full_width = FALSE) %>%
  column_spec(1, bold = TRUE) %>%
  collapse_rows(columns = 3:5, valign = "middle")

### Graph 1
suppressPackageStartupMessages(library(ggplot2))
df<-as.data.frame(centro_massa)
colnames(df) <-c("Latitude", "Longitude", "cluster")
g<-ggplot(data=dadoscompleto7,  aes(x=Longitude, y=Latitude,  color=factor(clusters))) + geom_point(aes(x=Longitude, y=Latitude), size = 4)
Centro_View<- g +  geom_text(data=dadoscompleto7, mapping=aes(x=eval(Longitude), y=eval(Latitude), label=Biogas), size=3, hjust=-0.1)+ geom_point(data=df, mapping=aes(Longitude, Latitude), color= "green", size=4) + geom_text(data=df, mapping = aes(x=Longitude, y=Latitude, label = 1:k), color = "black", size = 4) 
print(Centro_View + ggtitle("Gráfico de dispersão") + theme(plot.title = element_text(hjust = 0.5)))

Code for generating table and graph 2

###Table 2
dados_tabela <- Reduce(merge, list(dadoscompleto8, abrangencia, soma_biogas))
kable(dados_tabela[order(dados_tabela$cluster, as.numeric(dados_tabela$Propriedade)),c(2,5,1,6,7)], align = "c", row.names = FALSE) %>%
  kable_styling(full_width = FALSE) %>%
  column_spec(1, bold = TRUE) %>%
  collapse_rows(columns = 3:5, valign = "middle") 

### Graph 2
suppressPackageStartupMessages(library(ggplot2))
df<-as.data.frame(centro_massa)
colnames(df) <-c("Latitude", "Longitude", "cluster")
g<-ggplot(data=dadoscompleto7,  aes(x=Longitude, y=Latitude,  color=factor(clusters))) + geom_point(aes(x=Longitude, y=Latitude), size = 4)
Centro_View<- g +  geom_text(data=dadoscompleto8, mapping=aes(x=eval(Longitude), y=eval(Latitude), label=Biogas), size=3, hjust=-0.1)+ geom_point(data=df, mapping=aes(Longitude, Latitude), color= "green", size=4) + geom_text(data=df, mapping = aes(x=Longitude, y=Latitude, label = 1:k), color = "black", size = 4) 
print(Centro_View + ggtitle("Gráfico de dispersão") + theme(plot.title = element_text(hjust = 0.5))

Thankss!!

Try these,

Bests

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.