The shinydashboard package has three types of menus – messages, notifications, and tasks. I want to use the notifications menu for alerts. But I have to make some modications to the function. The image below is a demo of the notification menu from the package website (link). I want to remove the line that says "you have 3 notifactions" or change it to "you have three alerts". I want also to disable the toggle functionality and repalce the three icons at the top by "Today's Alerts" or something similar. The function to do this in the "dropdownMenu" function in shinydashboard. I can see the function source code by using
library(shinydashboard)
body(dropdownMenu)
but need help how to edit and use the modified source code.
I had to solve a similar problem in revising the answer I made for More efficient plot functions in R when millions of points are present?. Here's a version which is adapted to your needs:
my_dropdownMenu = function(...,
type = c("messages", "notifications", "tasks"),
badgeStatus = "primary", icon = NULL, .list = NULL)
{
message("Got here!")
# ...
# (COPY AND PASTE body(mydropdownMenu) HERE)
# (and then make your modifications)
}
# helper function, see
# https://stat.ethz.ch/pipermail/r-help/2008-August/171217.html
rebindPackageVar = function(pkg, name, new) {
# assignInNamespace() no longer works here, thanks nannies
ns=asNamespace(pkg)
unlockBinding(name,ns)
assign(name,new,envir=ns,inherits=F)
assign(name,new,envir=globalenv())
lockBinding(name,ns)
}
# make sure we can call non-exported functions (like validateStatus())
environment(my_dropdownMenu) = asNamespace("shinydashboard")
# now rebind the dropdownMenu function
rebindPackageVar("shinydashboard", "dropdownMenu", my_dropdownMenu);
Example output. The "Got here!" shows us that our modified version is being executed, and the rest is the normal output of the function:
> dropdownMenu()
Got here!
<li class="dropdown messages-menu">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<i class="fa fa-envelope"></i>
...
Related
I'm trying to do CSS animation in Elm, and I just can't get it to work!
Elm has several animation packages. The one I'm attempting to use is mdgriffith/elm-animator. Sadly, like many Elm packages, its documentation is sparse. It appears it provides two ways to render: one by running an Elm event loop to do a DOM update each frame, and one using CSS animation [which I didn't realise even existed]. I'm trying to do the latter.
I've tried to shrink the code down to a minimal example:
module Main exposing (main)
import Time
import Platform.Cmd
import Browser
import Html
import Html.Attributes
import Html.Events
import Color
import Svg
import Svg.Attributes
import Animator
import Animator.Css
main =
Browser.document
{
init = \ () -> ({fill = Animator.init <| Color.rgb 1 0 0}, Platform.Cmd.none),
subscriptions = \ state -> Animator.toSubscription Tick state animator,
view = \ state -> {title = "Animation test", body = view state},
update = \ msg state -> (update msg state, Platform.Cmd.none)
}
type alias State = { fill : Animator.Timeline Color.Color }
animator : Animator.Animator State
animator =
Animator.animator
|> Animator.Css.watching (\ state -> state.fill) (\ c state -> { state | fill = c })
type Msg = Tick Time.Posix | DoSomething
update : Msg -> State -> State
update msg state0 =
case msg of
Tick t -> Animator.update t animator state0
DoSomething -> { state0 | fill = Animator.go Animator.slowly (Color.rgb 1 1 0) state0.fill }
view : State -> List (Html.Html Msg)
view state0 =
[
Html.button [Html.Events.onClick DoSomething] [Html.text "Do something"],
Svg.svg
[
Svg.Attributes.width "100px",
Svg.Attributes.height "100px"
]
[
Animator.Css.node "circle"
state0.fill
[
Animator.Css.color
"fill"
(\ x -> x)
]
[
Svg.Attributes.cx "50",
Svg.Attributes.cy "50",
Svg.Attributes.r "50"
]
[]
]
]
I appreciate that's still pretty big, but I don't see how to easily make it much shorter without obfuscating what it's doing.
When I run this, the SVG fails to render. When I click the button, nothing happens.
Here's the really weird part: If I open the Firefox Inspector window, I can see the SVG <circle> element. If I edit its various properties, nothing happens. However, if I right-click the <circle> and select "Edit as HTML...", then add a single space to the element text and click off it, suddenly the circle appears! Moreover, if I right-click the element again, now it shows as "Edit as SVG...", which is suspicious.
Even more fun: If I load the page, click the button, and then do the above trick, the colour animation runs!
Note that if I edit the HTML and change nothing, it doesn't work. I have to make a trivial change to the text (or else I guess the browser decides it doesn't need to reprocess?)
I was so convinced this was going to end up being a weird Firefox bug... but then I tried it in Chrome and Edge, and it does exactly the same thing!
Does anybody have to vaguest clue why this doesn't work? Have I done something wrong with the Elm code? (I'm really, really struggling to figure out how this library works; I'm basically just guessing how the types fit together. So maybe I've done something dumb.)
This is due to a weird thing going on with namespaces. In an HTML document (i.e. on any webpage), the default namespace is the HTML namespace and if you want to render embedded documents in other formats, you need to ensure the nodes are created in the correct namespace.
Now when you write HTML as a string and the browser parses it from text, it will do this automatically for you:
<div> <!-- HTML Namespace -->
<svg>
<circle /> <!-- SVG Namespace -->
</svg>
<math>
<mrow></mrow> <!-- MathML namespace
(not really relevant, just pointing out different NS) -->
</math>
</div>
However, when you are constructing nodes dynamically (i.e. from JS or Elm), you need to explicitly ask for the namespace. That is in JS you would use Document.createElementNS() instead of just Document.createElement(). If you look at the source of the elm/svg package you will see that it does this:
node : String -> List (Attribute msg) -> List (Svg msg) -> Svg msg
node =
VirtualDom.nodeNS "http://www.w3.org/2000/svg"
If you don't do this, the browser understands you want to create a new HTML element called circle, which the browser doesn't know about. If the browser doesn't know about an element, it just treats basically like a <div>.
Now if you look at the source of the elm-animator package, you'll notice that it asks for an Html.node, so no namespace!
As to how to make it work with elm-animator, I suspect you can't. But perhaps someone else can contribute some solution...
Finally, you might want to consider SMIL style animation, it tends to get the job done without needing any external package.
I have implemented bootstrap 4 data table 4 in angular 4 but not able to change or modify row color. row selection color and header color as well.
I am using the data table 4 example : https://github.com/afermon/angular-4-data-table-bootstrap-4
and in this examples demo go through the demo 1 of link: https://afermon.github.io/angular-4-data-table-bootstrap-4-demo/
Considering the below code snippet present in data-table-component-demo1.ts got by the Git project you downloaded:
<data-table id="persons-grid"
[header] = "false"
[multiSelect] = "false"
[substituteRows]="false"
[indexColumn]="false"
[items]="items"
[itemCount]="itemCount"
(reload)="reloadItems($event)"
[pagination]="false"
(rowClick)="rowClick($event)"
[rowColors] = "callBackForChangineRowColors"
>
<data-table-column
[property]="'name'"
[header]="'Name'"
[sortable]="true"
[styleClass]="someExplicitClass"
In this, we can assign the value 'someExplicitClass' to [styleClass] as shown above and define the class someExplicitClass in our data-table-component-demo1.css file as below:
:host /deep/ .someExplicitClass{
background-color:red;
}
However, this is applied to the whole of the DataColumn and not controllable on a granular level.
We can indirectly apply only background-color using the rowEvent variable available within the rowClick(rowEvent) function of 'data-table-component-demo1.ts'
On click of the row, I will set the selected property of the row to true and thereby will trigger the onRowSelectChanged function of table.component.ts file
Now, once I set [rowColors] value to "callBackForChangineRowColors" as shown above and make the below changes in my data-table-component-demo1.component.ts file:
rowClick(rowEvent) {
console.log('Clicked: ' + rowEvent.row.item.name);
rowEvent.row.selected = true;
}
callBackForChangineRowColors(a,b,c)
{
if(b.selected)
return 'blue';
}
This way, I will be able to apply the color of blue explicitly for the selected Row.
*I could'nt unfortunately find any solution to apply any other styles on a granular level using a readily available input parameter like [styleClass] for it wasnt exposed as an #Input within our column.component.ts. If anyone has an idea, please do help me know it.
I have been working with shinyBS to create a set of collapsible panels. In the one shown below, only one panel should be open at a time (since the parameter multiple defaults to FALSE), but all three can be opened at the same time.
ui.R
library(shiny)
library(shinyBS)
shinyUI(fluidPage(
bsCollapse(
id = "stuff.all",
bsCollapsePanel(title = "Load Data", "Load the files"),
bsCollapsePanel(title = "Set Parameters", "Set the parameters"),
bsCollapsePanel(title = "Teacher Settings", "Choose the teachers")
)
))
server.R
library(shiny)
library(shinyBS)
shinyServer(function(input, output) {})
What is causing this bsCollapse to act as though multiple = TRUE, and how can I prevent it in the future?
Reference: https://ebailey78.github.io/shinyBS/docs/Collapses.html
I actually figured this out while writing the question, so I plan to answer my own question.
The id for bsCollapse in my example was "stuff.all". The fact that a period was part of the id seems to be what created the problem. When I changed the id to "stuff", the problem went away. When the id is "stuff.al" or "stuff.a", the problem persists. When the id is "stuff." or ".stuff", none of the panels expand when clicked. Given the way that bsCollapse works, the problem arises either from having a period in the id of an HTML <div> tag like so:
<div class="panel-group sbs-panel-group" data-sbs-multi="FALSE" id="stuff.a" role="tablist">
or from having a period in the data-toggle of an HTML <a> tag, like so:
<a data-toggle="collapse" href="#cpanel0758223" data-parent="#stuff.a">Load Data</a>
I'm using bootstrap-select to create my selectpicker.
I set an icon for the select using :
data-style="glyphicon glyphicon-list"
When I'm selecting an option, the option selected is place near the icon but I don't want that.
I don't want to see the selected option, only the icon.
Two printscreen to illustrate :
Before =>
http://hpics.li/07182fd
After =>
http://hpics.li/c1dd1ca
Thank you !
I found a way !
My code :
$('select.selectpicker').on('change', function(){
$(".glyphicon-list .filter-option.pull-left").empty();
});
glyphicon-list is the class of the button.btn.dropdown-toggle.selectpicker.
I've been playing with the animation package lately. Pretty nifty stuff but in the use of saveHTML I get a control panel with a green dot for every image (see below) and I have a ton of images. How can I make the green dots go away but keep the control panel?
I asked a related question yesterday so the minimal working example is there (my data set and mnel's answer).
Here's the code I'm using to make the html file:
saveHTML(pp(), autoplay=FALSE, loop=FALSE, verbose=FALSE, outdir = "new")
The animation help manual says see the reference for a complete list of available options but I can not figure out how to do what I've asked above.
You want to remove the 'navigator' option from 'controls'. Try adding this to the parameter list: single.opts = "'controls': ['first', 'previous', 'play', 'next', 'last', 'loop', 'speed'], 'delayMin': 0"
to get something like:
saveHTML(pp(), autoplay=FALSE, loop=FALSE,
verbose=FALSE, outdir = "new",
single.opts = "'controls': ['first', 'previous', 'play', 'next', 'last', 'loop', 'speed'], 'delayMin': 0")
The default list includes 'navigator' so we're just removing that option. You can reorder these options too if you want.