Shiny-Server (AWS Ubuntu) Not rendering ShinyDashboard correctly - shiny-server

Thank you for your help in advance.
I've setup shiny server on Ubuntu in Amazon Web Services. Everything is working correctly with other apps I've uploaded. However, I'm trying to use the package shinydashboards to create some dashboards. I'm running into an issue where the first submenu item is not being rendered.
You can see the app live in AWS here. https://www.ndperfsci.com/apps/TestApps/PerfSci_App/
It functions just fine in ShinyApps.io
https://webbphysprep.shinyapps.io/test/
Here is the exact code I'm using:
library('shiny')
library('shinydashboard')
# Sidebar #############################
sidebar <- dashboardSidebar(
sidebarMenu(
menuItem('Catapult', tabName = 'menu_ctplt', icon = icon('circle-o'),
collapsible =
menuSubItem('Upload Files', tabName = 'submenu_ctplt_upload'),
menuSubItem('Edit Records', tabName = 'submenu_ctplt_edit')
)
),
sidebarMenu(
menuItem('Force Decks', tabName = 'menu_fd', icon = icon('circle-o'),
collapsible =
menuSubItem('Upload Files', tabName = 'submenu_fd_upload'),
menuSubItem('Edit Records', tabName = 'submenu_fd_edit')
)
)
)
# Body #############################
body <- dashboardBody(
tabItems(
tabItem(tabName = 'submenu_ctplt_upload',
h2('Selected Sub-Item One')
),
tabItem(tabName = 'submenu_ctplt_edit',
h2('Selected Sub-Item Two')
),
tabItem(tabName = 'submenu_fd_upload',
h2('Selected Sub-Item Three')
),
tabItem(tabName = 'submenu_fd_edit',
h2('Selected Sub-Item Four')
)
)
)
# UI #############################
ui <- dashboardPage(
dashboardHeader(title = 'ND Perf-Sci Apps'),
skin = 'black',
sidebar,
body
)
# Server #############################
server <- function(input, output){
}
shinyApp(ui, server)

Related

Is there a way to pass the 'bazel run' result file to the next rule file in bazel?

I created a first rule file to geneate a scirpt using the ctx.actions.expand_template and ran it. and I wanted that pass the result of bazel run with first rule to the next 2nd rule file as a resource. But, I could't get the result which is generated by bazel run 1st rule in the 2nd rule.
It does not mean the script created by the first rule, but the file created when the script is executed.
Below example is what I tested.
This is bazel rule file
def _1st_rule_impl(ctx):
...
out = ctx.outputs.executable
template = ctx.file.my_template
ctx.actions.expand_template(
output = out,
template = template,
substitutions = {
"{ARG1}: ctx.attr.my_file_name,
"{ARG2}: ctx.attr.my_file_content,
}
return [
DefaultInfo(
files = depset([out]),
runfiles = ctx.runfiles(files = [out])
)
]
1st_rule = rule(
implementation = _1st_rule_impl,
attrs = {
"my_template":attr.label(
allow_single_file = True,
default = Label("#my_test//my_rules:my_script.sh.template"),
),
"my_file_name": attr.string(
default = "myfile.txt",
),
"my_file_content": attr.string(
default = "hello world",
),
},
executable = True,
)
def _2nd_rule_impl(ctx):
...
for dep in ctx.attr.deps:
//
// HOW CAN I GET THE RESULT OF `bazel run` THE '1st_rule'?
// I WANT TO GET THE `myfile.txt` WHICH IS GENERATED BY '1st_rule'
//
return [
DefaultInfo(
files = depset([out]),
runfiles = ctx.runfiles(files = [out]),
)
]
2nd_rule = rule(
implementation = _2nd_rule_impl,
attrs = {
"dep":attr.label_list(
mandatory= True,
),
...
},
executable = True,
)
This is BUILD file
1st_rule(
name = "my_1st_rule",
my_file_name = "myfile.txt",
my_file_content = "hello world",
)
2nd_rule(
name = "my_2nd_rule",
dep = [
":my_1st_rule",
],
)
This is template shell script
...
function create_file() {
echo "{ARG2}" > "{ARG1}"
}
...
I tested with the example described above.
There are several ways to access the outputs of dependencies. Perhaps, the simplest is ctx.files. For example, print(ctx.files.dep) in _2nd_rule_impl should show the output of my_1st_rule when my_2nd_rule is analyzed.

How can I import from multiple files in r-drake?

I want to import data of a similar category from multiple source files.
Every source has a short label.
How can I incorporate this into drake, without writing out every file as its own target?
I thought the following would work, but it does not. Ideally, I would like to have the targets raw_a and raw_b.
input_files <- list(
'a' = 'file_1.csv',
'b' = 'file_2.csv'
)
plan <-
drake::drake_plan(
raw = drake::target(
import_file(file),
transform = map(
file = file_in(!! input_files)
)
)
)
with
import_file <- function(file) {
readr::read_csv(file, skip = 2)
}
You are so close. file_in() needs to go literally in the command, not the transformation.
library(drake)
input_files <- c("file_1.csv", "file_2.csv")
plan <- drake_plan(
raw = target(
import_file(file_in(file)),
transform = map(file = !!input_files)
)
)
config <- drake_config(plan)
vis_drake_graph(config)
Created on 2019-10-19 by the reprex package (v0.3.0)
This is probably the idiomatic solution.
plan <-
drake::drake_plan(
raw = drake::target(
import_file(file),
transform = map(
file = file_in('file_1.csv', 'file_2.csv'),
label = c('a', 'b'),
.id = label
)
)
)
file_in needs to around the whole string
plan <-
drake::drake_plan(
raw = drake::target(
import_file(file),
transform = map(
file = list(
file_in('file_1.csv'),
file_in('file_2.csv')
)
)
)
)

Save and restore selections in a shinyTree

Is it possible to save and restore selections of a shinyTree?
I found a solution deleting the selections
R Shiny - Updating shinyTree node selections
but I need to save the selections and restore them later for example, by an actionButton
This is not possible with shinyTree only. Some functions of the underlying jsTree library have to be called directly and the values passed from JavaScript to R and vice-versa.
I made a small example, which should help you as a starting point.
If you save a selection via button-click, R sends a custom message to JavaScript, which will get the selected IDs and returns it to R via Shiny.setInputValue.
The selected ID's are then saved in the reactiveValues selectionRV, but you could save them in a file or database if needed.
library(shiny)
library(shinyTree)
library(shinyjs)
js <- HTML("
$(document).on('shiny:connected', function(event) {
Shiny.addCustomMessageHandler('saveselection', function(e) {
var selection = $('#tree').jstree().get_selected();
Shiny.setInputValue('treeselection', selection, {priority: 'event'});
});
})
")
## ui ####################
ui <- fluidPage(
useShinyjs(),
tags$head(tags$script(js)),
actionButton("deselect", "Deselect all"),
actionButton("savesele", "Save Selection"),
actionButton("restoresele", "Restore Selection"),
shinyTree("tree", dragAndDrop = TRUE,types= #Types is in the same format that jstree expects
"{
'#': { 'max_children' : 2, 'max_depth' : 4, 'valid_children' : ['root'] },
'root' : { 'valid_children' : ['file'] },
'default' : { 'valid_children' : ['default','file'] },
'file' : { 'icon' : 'fa fa-file', 'valid_children' : [] }
}"
)
)
## server ####################
server <- function(input, output, session) {
treeData <- reactive({
rootstrc <- structure(list(
SubListA = structure(list(
leaf1 = structure("",sttype="file",sticon="fa fa-signal"),
leaf2 = structure("",sttype="file",sticon="fa fa-signal"),
leaf3 = structure("",sttype="file",sticon="fa fa-signal")),
sttype="root",stopened=F,sticon="fa fa-signal"
),
SubListB = structure(list(
leafA = structure("",sttype="default",sticon="glyphicon glyphicon-leaf"),
leafB = structure("",sttype="default",sticon="shinyTree/icon.png"),
leafC = structure("",sttype="default",sticon="fa fa-signal")
),stopened=F,sttype="root",sticon="fa fa-signal")
),
sttype="root",stopened=F,sticon="fa fa-signal"
)
list(
root1 = rootstrc,
root2 = rootstrc,
root3 = rootstrc,
root4 = rootstrc
)
})
output$tree <- renderTree({
treeData()
})
selectionRV <- reactiveValues(list = NULL)
observeEvent(input$deselect, {
runjs("$('#tree').jstree().deselect_all()")
})
observeEvent(input$savesele, {
session$sendCustomMessage("saveselection", message)
})
observeEvent(input$restoresele, {
req(input$treeselection)
tmp <- paste0("[", paste(input$treeselection, collapse = ","), "]")
js <- sprintf("$('#tree').jstree().select_node(%s)", tmp)
runjs(js)
})
}
shinyApp(ui, server)

Using percent width for Rcharts

I was wondering how to set the width of an rChart using % as opposed to px. I noticed in the source code that it defaults to pixels. I'm trying to use it in a shiny app, and fixed with charts seem to be an issue as they don't scale with the rest of the user interface. Is there a way around this?
This should be considered a hack, since neither rCharts or most of the libraries have built in responsive behavior. However, one change would be to define your own renderChart function with this behavior. Something like this might work if you define in the server piece of shiny.
renderChart_pct <- function(expr, env = parent.frame(), quoted = FALSE) {
func <- shiny::exprToFunction(expr, env, quoted)
function() {
rChart_ <- func()
cht_style <- sprintf("<style>.rChart {width: %s; height: %s} </style>",
#### change these here to desired %
"100%", "100%")
cht <- paste(capture.output(rChart_$print()), collapse = '\n')
HTML(paste(c(cht_style, cht), collapse = '\n'))
}
}
Then use renderChart_pct instead of renderChart2. You'll probably notice that the result will not be truly responsive. Altogether, here would be an example with dPlot.
library(shiny)
library(rCharts)
renderChart_pct <- function(expr, env = parent.frame(), quoted = FALSE) {
func <- shiny::exprToFunction(expr, env, quoted)
function() {
rChart_ <- func()
cht_style <- sprintf("<style>.rChart {width: %s; height: %s} </style>",
"100%", "100%")
cht <- paste(capture.output(rChart_$print()), collapse = '\n')
HTML(paste(c(cht_style, cht), collapse = '\n'))
}
}
ui = shinyUI(fluidPage(
fluidRow(
column(4,
h1("Filler Header")
)
,column(8,
div (
showOutput("myChart", "dimple")
)
)
)
))
server = function(input,output){
output$myChart <- renderChart_pct({
d = dPlot(
x~x
, data = data.frame(x=1:10)
, type = "line"
, height = 500
, width = NULL
)
})
}
runApp( list(ui=ui,server=server))

ATCTContent created with wrong id and title

I've made an add-on with several ATCTContent, all created with paster addcontent contenttype. All but one, GearContent work as expected. Only when I create instances of GearContent they receive names like gear, gear-1, etc. ignoring the title. In default view, the H1 tag is always 'Gear' but the title bellow it is right.
Trying to change the ids and titles on the folder content view doesn't do anything. There's no error message.
Same thing with the catalog. GearContent's Title metadata is 'Gear' for all instances. It works for all other types.
GearContent is only addable inside GearFolder. Other contents have similar restrictions and work fine. I'm using plone 4.0.4.
What can I do to make new instances get the title right?
Below content/gearcontent.py:
"""Definition of the Gear Content content type
"""
from zope.interface import implements
from Products.Archetypes import atapi
from Products.ATContentTypes.content import base
from Products.ATContentTypes.content import schemata
# -*- Message Factory Imported Here -*-
from levity7.gears import gearsMessageFactory as _
from levity7.gears.interfaces import IGearContent
from levity7.gears.config import PROJECTNAME
GearContentSchema = schemata.ATContentTypeSchema.copy() + atapi.Schema((
# -*- Your Archetypes field definitions here ... -*-
atapi.StringField(
'title',
storage=atapi.AnnotationStorage(),
widget=atapi.StringWidget(
label=_(u"Title"),
description=_(u"Name for this content."),
),
required=True,
),
atapi.ReferenceField(
'activities',
storage=atapi.AnnotationStorage(),
widget=atapi.ReferenceWidget(
label=_(u"Adventure Activities"),
description=_(u"Select all activities that apply to this content."),
),
required=True,
relationship='gearcontent_activities',
allowed_types=('Gear Activity'), # specify portal type names here ('Example Type',)
multiValued=True,
),
atapi.ReferenceField(
'category',
storage=atapi.AnnotationStorage(),
widget=atapi.ReferenceWidget(
label=_(u"Category"),
description=_(u"Select a category for this content."),
),
required=True,
relationship='gearcontent_category',
allowed_types=('Gear Category'), # specify portal type names here ('Example Type',)
multiValued=False,
),
atapi.ImageField(
'image',
storage=atapi.AnnotationStorage(),
widget=atapi.ImageWidget(
label=_(u"Image"),
description=_(u"A picture of this content."),
),
validators=('isNonEmptyFile'),
),
atapi.StringField(
'imageLink',
storage=atapi.AnnotationStorage(),
widget=atapi.StringWidget(
label=_(u"Image Link"),
description=_(u"An URL to the image of this content."),
),
validators=('isURL'),
),
atapi.TextField(
'description',
storage=atapi.AnnotationStorage(),
widget=atapi.RichWidget(
label=_(u"Description"),
description=_(u"Description for the content."),
),
required=True,
),
atapi.StringField(
'reviewLink',
storage=atapi.AnnotationStorage(),
widget=atapi.StringWidget(
label=_(u"Review Link"),
description=_(u"Link to Review page."),
),
validators=('isURL'),
),
atapi.StringField(
'diyLink',
storage=atapi.AnnotationStorage(),
widget=atapi.StringWidget(
label=_(u"DIY Link"),
description=_(u"Link to DIY page."),
),
validators=('isURL'),
),
atapi.TextField(
'commentary',
storage=atapi.AnnotationStorage(),
widget=atapi.TextAreaWidget(
label=_(u"commentary"),
description=_(u"commentarys for the content. These will not be displayed."),
),
),
atapi.TextField(
'purchaseHtml',
storage=atapi.AnnotationStorage(),
widget=atapi.TextAreaWidget(
label=_(u"Purchase HTML Code"),
description=_(u"HTML used to display or add this item to the Cart."),
),
),
atapi.IntegerField(
'score',
storage=atapi.AnnotationStorage(),
widget=atapi.IntegerWidget(
label=_(u"Life This Value"),
description=_(u"Initial value of 'Life This'"),
),
default=_(u"0"),
validators=('isInt'),
),
))
# Set storage on fields copied from ATContentTypeSchema, making sure
# they work well with the python bridge properties.
GearContentSchema['title'].storage = atapi.AnnotationStorage()
GearContentSchema['description'].storage = atapi.AnnotationStorage()
schemata.finalizeATCTSchema(GearContentSchema, moveDiscussion=False)
class GearContent(base.ATCTContent):
"""Gear Content"""
implements(IGearContent)
meta_type = "GearContent"
schema = GearContentSchema
title = atapi.ATFieldProperty('title')
description = atapi.ATFieldProperty('description')
# -*- Your ATSchema to Python Property Bridges Here ... -*-
title = atapi.ATFieldProperty('title')
activities = atapi.ATReferenceFieldProperty('activities')
category = atapi.ATReferenceFieldProperty('category')
image = atapi.ATFieldProperty('image')
imageLink = atapi.ATFieldProperty('imageLink')
description = atapi.ATFieldProperty('description')
reviewLink = atapi.ATFieldProperty('reviewLink')
diyLink = atapi.ATFieldProperty('diyLink')
commentary = atapi.ATFieldProperty('commentary')
purchaseHtml = atapi.ATFieldProperty('purchaseHtml')
score = atapi.ATFieldProperty('score')
atapi.registerType(GearContent, PROJECTNAME)
Thanks.
Remove your "title" field. It's already defined in ATContentTypeSchema. You're effectively re-implementing it, but without the baseline functionality like automatic content object naming. Yours is masking the one defined in Archetypes.
The problem was in the field category. It seems that's a reserved name. (in the above it appears 'categoty'; it was a typo).

Resources