Import

To create a shiny widget the data is assumed to be of class likertData, which basically consists of three data frames.

  library('knitr')
  library(shinyLikert)      # load the package from installed library
  #require( 'devtools' )
  #devtools::load_all( "../.." ) # load the package from source
  testData2 = createTestData()
 testData3 = createTestData()
 plot( 
    renderShinyLikert( testData3 )  
  )

The structure of the data is as follows

  summary( testData2 )
  fluidPage( renderFactorOverview( testData2 ) )

The dropdown menu lets you choose a factor and the plot element displays a bar chart of the factor levels. Since the testData2 is generated with a uniform distribution, the factor levels are equally distributed.

We used the dataset testData2 here. This data consists of three data frames.

  names( testData2 )

The first data frame likert_data consists of the likert items. The row names are the participant IDs and the column names are the questions of the of the survey.

  kable( head( testData2$likert_data[,1:6] ) )

The second data frame row_factors can be used to classify the participants.

  kable( head( testData2$row_factors ) )

The third data frame column_factors can be used to classify the questions.

  kable( head( testData2$column_factors ) )

Simple usuage

To display the likert_data, use the renderShinyLikert function

 plot( renderShinyLikert( testData2 ) )  

This function can be used in the following way

  renderShinyLikert( 
        dataset , dropdown_factor )

The dataset is assumed to be of class likertData. The output is a list contining the plot and the control element. They can be used like here

  rendered2 = renderShinyLikert( 
        testData2,
        dropdown = "country" )
  rendered2$selector
  rendered2$plot

wich produces the following output.

  rendered2 = renderShinyLikert( 
        testData2 ,
        dropdown = "country" )
  rendered2$selector
  rendered2$plot
  dataTableOutput( "ID 1.factorTable" )

The factors to be used in dropdown can be either row factors or column factors called by name. The dataset is filtered according to those factors prior to plotting. If you want to filter by question, just add another column to testData2$column_factors

  testData2$column_factors = cbind( testData2$column_factors,
                                    question = paste( "Question", 
                                                      1:10 )
  )

and now change the dropdown argument fom country to c("difficulty", "question")

  rendered2.1 = renderShinyLikert( 
                                   testData2,
                                   dropdown = c("difficulty",
                                                "question") )
  rendered2.1$selector
  rendered2.1$plot

Ui/Server setup

To use this function in a ui/server setup, you can use the following syntax

shinyApp(
    ui= fluidPage(
        uiOutput("selector"),
        uiOutput( "plot" )
      ),
    server = function( input, output, session ){
      testData3 = createTestData()
      rendered = renderShinyLikert( 
        testData3 ,
        dropdown = "gender" )
      output$plot = rendered$plot
      output$selector = rendered$selector
    }
  )

Input options

Several dropdown inputs

output$selector is the inputpanel which lets you select the gender in this case. To add more inputs, from them together in a list.

    rendered3 = renderShinyLikert( 
        testData2,
        dropdown = c( "country", "difficulty" )
    )
  rendered3$selector
  rendered3$plot

You can also use column_factors exactly as above.

  plot(
    renderShinyLikert( 
        testData2,
        dropdown = c( "difficulty" )
    )
  )

Height

To control the height of the plot, use the option height = c( height_min, height_max )

  plot( 
    renderShinyLikert( 
      testData2, 
      dropdown = c( "gender", "country" ),
      height = c( 300, 600 )
    ) 
  )

Responselevels

To get a custom order for the responses, use the responselevels parameter

  plot( 
    renderShinyLikert( 
      testData2,
      dropdown = "gender",
      response_levels = c( "Strongly Agree", "Agree", "Neutral" )
      ) 
  )

Pass arguments to HH::likert

You can also pass down arguments down to HH::likert

  plot( 
    renderShinyLikert( 
      testData2,
      dropdown = "country",
      main = "custom_title",
      horizontal = FALSE,
      as.percent = TRUE,
      positive.order = TRUE
    ) 
  )

You can also use the names of column_factors for the dropdown argument.

  plot( 
    renderShinyLikert( 
      testData2,
      dropdown = "difficulty"      ) 
  )

split_factors

For factror analysis, you can also use the split_factors argument.

  plot( 
    renderShinyLikert( 
      testData2,
      split    = c( "difficulty", "gender", "country" )
    ) 
  )
  plot( 
    renderShinyLikert( 
      testData2 ,  
      dropdown = "country",
      split    = "difficulty"
    ) 
  )

Grouping data with the likert package

  plot( 
    renderShinyLikert( 
      testData2,
      height  = c(500,800),
      dropdown = c("gender","difficulty"),
      group = "country"
    ) 
  )
  plot( 
    renderShinyLikert( 
      testData2,
      height  = c(500,800),
      dropdown = c("country","difficulty"),
      group = "gender",
      grouping = "HH"
    ) 
  )


GregorDeCillia/shinyLikert documentation built on May 6, 2019, 6:36 p.m.