What is the output function for both Kable and Highcharter function

Hi Experts. With the help of member I am able to learn R shiny beyond my limits and thanks a lot for that. However I do face some problems like below. Appreciate if anyone could help me

If I run the below code, I get htmloutput(Kable function) as per filters. But I am trying get a plot called highcharter(already coded below) in the same output (below html output). So basically when I filter "Mill-A", there should be 2 outpluts (1 is HTML table and another is highcharter).

I am not sure which output function should I use so that both HTML and highcharter is rendered. I tried putting renderplot but not possible. It is showing an error.

Right now what I have done is, I have just included both outputs just below each other. I am thinking by doing this way also, I should get the output right? Please guide on this?

---
title: "Untitled"
runtime: shiny
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    vertical_layout: scroll
    theme: cosmo
---

```{r setup, include=FALSE}
library(flexdashboard)
library(readxl)
library(tidyverse)
library(formattable)
library(highcharter)
library(reshape)
library(shiny)
library(knitr)
library(kableExtra)
```


```{r}
Past_Maintainence <- structure(list(Mill = c("Mill-A", "Mill-B"), `Electrical Maintainence done` = structure(c(1569283200, 
1569369600), class = c("POSIXct", "POSIXt"), tzone = "UTC"), 
    `Instrumentation Maintainence done` = structure(c(1569369600, 
    1569456000), class = c("POSIXct", "POSIXt"), tzone = "UTC"), 
    `Mechanical Maintainence done` = structure(c(1569456000, 
    1569283200), class = c("POSIXct", "POSIXt"), tzone = "UTC"), 
    Performance = c(0.5, 0.6)), row.names = 1:2, class = "data.frame")
`Mill-A` <- structure(list(air_flow = c(5, 10), max_air = c(14.2, 28.4), 
    min_air = c(7.6, 15.2), stabality_min_coal = c(46.5, 46.5
    ), explosion_limit = c(25, 50), min_air_flowfall_out_limt = c(113.8, 
    113.8), max_coal_flow = c(93, 93), normal_coal_flow = c(84.12, 
    84.12), max_air_flow_erosion_limit = c(162.5, 162.5), fan_power = c(256, 
    251)), row.names = c(NA, -2L), class = c("tbl_df", "tbl", 
"data.frame"))
```

Summary
=================

Inputs {.sidebar}
-----------------------------------------------------------------------

```{r}
    selectInput("Mill1","Equipment",choices = c("All","Mill-A"),selected = "All",multiple = TRUE)
```

Row {.tabset .tabset-fade}
-----------------------------------------------------------------------

### Performance {data-width=10}

```{r}
output$combined_plot1 <- renderText({
  req(input$Mill1)
  table_data <- Past_Maintainence
  if (input$Mill1 != "All"){
    table_data <- Past_Maintainence %>% filter(Mill %in% input$Mill1)
  }
  table_data %>% mutate(Performance = color_bar("lightgreen")(Performance)) %>% select(everything()) %>% kable(escape = F,caption = "Title") %>% kable_styling("hover", full_width = F)
})
htmlOutput("combined_plot1")

output$combined_plot <- renderHighchart({
  req(input$Mill1)
  if (input$Mill1 != "All"){
    plot_data <- input$Mill1
    design_melt <- subset(plot_data, select = -c(max_coal_flow, normal_coal_flow))
    melted <- as.data.frame(melt(design_melt, id='air_flow'))
  }
  hc_marker <- highchart()%>%
  hc_add_series(melted, "line", hcaes(x = value, y = air_flow, group = variable))%>%
  hc_add_series(`Mill-A`, "line", hcaes(x = air_flow, y = max_coal_flow), name = "max_coal_flow")%>%
  hc_add_series(`Mill-A`, "line", hcaes(x = air_flow, y = normal_coal_flow), name = "normal_coal_flow")%>%
  hc_add_series(`Mill-A`, "line", hcaes(x = air_flow, y = stabality_min_coal), name = "stabality_min_coal")%>%     
  hc_add_series(Real_time_Parameters,"point",hcaes(x=X,y=Y,group = Parameters)) %>% 
  hc_xAxis(min = 70, max = 250)%>%hc_yAxis(min = 15, max = 140)
  print(hc_marker)
})

highchartOutput("combined_plot")
```

I think you should put one output for each and this is what you are doing so everything seems fine.
Do you get some error ?

Error in the sense. If I follow the same code as above, I get only one output (combined_plot1) and other output (combined_plot) is not displayed.

And yes as you mentioned I have put output separately

Wanted to check if you want to me to give more details on this?

I can't make your example work

  • melted does not exists for input$Mill1 == "All"
  • Real_time_Parameters does not exist either

I also think kable is not to be used with renderText. See this example
https://cran.r-project.org/web/packages/kableExtra/vignettes/use_kable_in_shiny.html

Also, I don't think you need an explicit print call for renderHighchart. See this example too

1 Like

thanks, But still confused. Ok. I will try to manage this. However can you let me know which output function to use so that both kable and highcharter are rendered? Then I will try myself

You need to have one output per output.
You have two outputs : A table using kable, and a plot using highchart.

You can use one for both.

If you want to organize your page differently to have both output in same box or something like, you need CSS customization, or a more customizable framework than flexdashboard, which is already organizing the page for you.

I may have misunderstood your question nd some precisions about what you seek can help me better understand.

Currently, the example you provide don't run on my side (no app is launched) so I can't really try and see what is the issue.

2 Likes

ok. I am not able to edit my question. Not sure why. I can post new code for you

Hi I have added a different question here

Please help

Thanks. will try......................