Charles Stangor
Charles Stangor

Reputation: 304

formatter output doesn't appear in shiny

Can I make my shiny app use the formats applied in formatter?

The first column prints in green when listed, but not in the shiny.

ft <- formattable(mtcars,
            list(mpg = formatter("span", style = "color:green")))

#mpg prints green here:
ft

app = shinyApp(
  ui = fluidPage(
    fluidRow(
      column(12,
             formattableOutput('table')

      )
    )
  ),
  server = function(input, output) {
    #but not here
    output$table <- renderFormattable({formattable(ft, list())})
      }
)

Upvotes: 0

Views: 273

Answers (1)

Wilmar van Ommeren
Wilmar van Ommeren

Reputation: 7689

You are calling the function formattable twice. Second time in the app with an empty list() containing no format options. Basically you are overwiting the format that you defined earlier, with an empty format. To solve this there are two options.

One is to define your table outside the app and render the output without overwriting the format:

output$table <- renderFormattable({ft})

But it is also possible to define the table and format options inside you server:

output$table <- renderFormattable({formattable(mtcars,
                                                   list(mpg = formatter("span", style = "color:green")))})

Upvotes: 1

Related Questions