# [Task Request] Improvement in the Steemg code struction to avoid copying over similar code

https://github.com/pzhaonet/steemg

#### Details

Steemg (website: http://steemg.org) is an online tool which collects and analyzes the data of steem activities and contests. Steemg displays all the related posts of an activity or contest, even if some of them are too old to find on steemit.com. The participation frequency of each author is summarized. Participants and organizers of the activity can see the statistic analysis figures. For more information about the project you can read an brief introduction in one of my previous post: [New Project] steemg: an online collection and analysis tool for steem activities and contests. Thanks to the support from utopian.io!

There are currently four tabs on Steemg. Each tab displays the data of one contest with a similar structure including a table of posts, a table of authors, and statistic analysis figures. More tabs will be available in the future.

When I submitted one of my contribution reports to utopian.io, a moderator gave me a kind suggestion:

You could possibly refactor your code so that next time if you add a new tab e.g. statistics about a new tag, you don’t have to copy over quite similar code.

I totally agree that my code could be improved. In fact, I tried using user-defined functions and packages in my code. However, it seems difficult to apply these functions to the webpage elements in such a Shiny-App. The details are as follows.

You could see the similar structure on the four tabs. For example, the tab of the CN-Kids contest and the one of the CN-Green contest look like:

and

respectively. There are check box groups, radio buttons, data tables, figures etc.. Let’s see the R code for a check box group in the ui.R file of these two tabs are:

checkboxGroupInput(
inputId = "cngreen_colsel",
label   = "选择显示哪些列:",
choices = c('date', 'author', 'title', 'payout','votes'), #'level',
selected = c('date', 'author', 'title', 'payout','votes'),
inline = TRUE
)


and

checkboxGroupInput(
inputId = "cnkids_colsel",
label   = "选择显示哪些列:",
choices = c('date', 'author', 'title', 'payout','votes'), #'level',
selected = c('date', 'author', 'title', 'payout','votes'),
inline = TRUE
)


respectively. You can see the strings "cngreen_colsel" and "cnkids_colsel", which call the element ID in the server.R file:

  output$cngreen_dt1 = renderDataTable({ ... mymatcngreenout <- mymatcngreen[, c('Rank', input$cngreen_colsel)]
...
}


and

  output$cnkids_dt1 = renderDataTable({ ... mymatcnkidsout <- mymatcnkids[, c('Rank', input$cnkids_colsel)]
...
}


respectively. You could imagine that there will be more element IDs in the future if more contests are brought into Steemg. The question is: how can ui.R call the element ID server.R in a better way if there are similar tabs? It would be easy in normal R functions, but I do not know how to do it in a Shiny-app.

If someone could contribute to the improvement of the code in this aspect, then I do not have to copy over quite similar codes. There are many many such cases in Steemg.

#### Components

• The web interface will no change. Only the code structure will be improved.